﻿
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ES6规范 · Sqlrule</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Sqlrule">
        
        
    
    <link rel="stylesheet" href="css/style.css">

    
            
                
                <link rel="stylesheet" href="css/search.css">
                
            
                
                <link rel="stylesheet" href="css/plugin.css">
                
            
                
                <link rel="stylesheet" href="css/splitter.css">
                
            
                
                <link rel="stylesheet" href="css/plugin_1.css">
                
            
                
                <link rel="stylesheet" href="css/website.css">
                
            
                
                <link rel="stylesheet" href="css/website_1.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="JavaScript_ES5_ReleasedVersion.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    认证体系概览
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" >
            
                <span>
            
                    
                    Oracle规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1.1" data-path="../../Database/design_Oracle/design_Oracle_ReleasedVersion.html">
            
                <a href="../../Database/design_Oracle/design_Oracle_ReleasedVersion.html">
            
                    
                    设计规范 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.1.2" data-path="../../Database/dev_Oracle/dev_Oracle_ReleasedVersion.html">
            
                <a href="../../Database/dev_Oracle/dev_Oracle_ReleasedVersion.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.1.3" data-path="../../Database/operation_Oracle/operation_Oracle_ReleasedVersion.html">
            
                <a href="../../Database/operation_Oracle/operation_Oracle_ReleasedVersion.html">
            
                    
                    运维规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.2" >
            
                <span>
            
                    
                    MySQL规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.2.1" data-path="../../Database/design_MySQL/design_MySQL_ReleasedVersion.html">
            
                <a href="../../Database/design_MySQL/design_MySQL_ReleasedVersion.html">
            
                    
                    设计规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.2" data-path="../../Database/dev_MySQL/dev_MySQL_ReleasedVersion.html">
            
                <a href="../../Database/dev_MySQL/dev_MySQL_ReleasedVersion.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.3" data-path="../../Database/operation_MySQL/operation_MySQL_ReleasedVersion.html">
            
                <a href="../../Database/operation_MySQL/operation_MySQL_ReleasedVersion.html">
            
                    
                    运维规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3" >
            
                <span>
            
                    
                    TimesTen规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.1" data-path="../../Database/design_TimesTen/design_TimesTen_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.2" data-path="../../Database/dev_TimesTen/dev_TimesTen_ReleasedVersion.html">
            
                <a href="../../Database/dev_TimesTen/dev_TimesTen_ReleasedVersion.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3" data-path="../../Database/operation_TimesTen/operation_TimesTen_ReleasedVersion.html">
            
                <a href="../../Database/operation_TimesTen/operation_TimesTen_ReleasedVersion.html">
            
                    
                    运维规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.4" >
            
                <span>
            
                    
                    QMDB规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.4.1" data-path="../../Database/design_QMDB/design_QMDB_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.4.2" data-path="../../Database/dev_QMDB/dev_QMDB_ReleasedVersion.html">
            
                <a href="../../Database/dev_QMDB/dev_QMDB_ReleasedVersion.html">
            
                    
                    开发规范(建设中)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.4.3" data-path="../../Database/operation_QMDB/operation_QMDB_ReleasedVersion.html">
            
                <a href="../../Database/operation_QMDB/operation_QMDB_ReleasedVersion.html">
            
                    
                    运维规范(建设中)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.5" >
            
                <span>
            
                    
                    HBase规范(建设中)
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.5.1" data-path="../../Database/design_HBase/design_HBase_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.2" data-path="../../Database/dev_HBase/dev_HBase_ReleasedVersion.html">
            
                <a href="../../Database/dev_HBase/dev_HBase_ReleasedVersion.html">
            
                    
                    开发规范（建设中）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.3" data-path="../../Database/operation_HBase/operation_HBase_ReleasedVersion.md">
            
                <span>
            
                    
                    运维规范（暂缺）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.6" >
            
                <span>
            
                    
                    Redis规范(建设中)
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.6.1" data-path="../../Database/design_Redis/design_Redis_ReleasedVersion.md">
            
                <span>
            
                    
                    设计规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6.2" data-path="../../Database/dev_Redis/dev_Redis_ReleasedVersion.md">
            
                <span>
            
                    
                    开发规范（暂缺）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6.3" data-path="../../Database/operation_Redis/operation_Redis_ReleasedVersion.html">
            
                <a href="../../Database/operation_Redis/operation_Redis_ReleasedVersion.html">
            
                    
                    运维规范（建设中）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.7" >
            
                <span>
            
                    
                    Java开发规范(建设中)
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.7.1" data-path="../Java/Java_ReleasedVersion.html">
            
                <a href="../Java/Java_ReleasedVersion.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.2" >
            
                <a target="_blank" href="http://gitlab.iwhalecloud.com/CoP/Java-Coding-Specification/-/blob/master/jcs-Alibaba/%E3%80%8AJava%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%E3%80%8Bv1.5.0%20%E5%8D%8E%E5%B1%B1%E7%89%88.pdf">
            
                    
                    《Java开发手册》v1.5.0 华山版（在线版建设中）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.3" data-path="../Java/operation_JVM_ReleasedVersion.html">
            
                <a href="../Java/operation_JVM_ReleasedVersion.html">
            
                    
                    虚拟机运维规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.4" >
            
                <a target="_blank" href="http://gitlab.iwhalecloud.com/CoP/Java-Coding-Specification/-/blob/master/CERT-Standard/QIWC_33.001.1_2019%E6%B5%A9%E9%B2%B8%E7%A7%91%E6%8A%80Web%E5%BA%94%E7%94%A8%E5%AE%89%E5%85%A8%E5%BC%80%E5%8F%91%E8%A7%84%E8%8C%83.pdf">
            
                    
                    WEB应用安全开发规范（在线版建设中）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7.5" >
            
                <a target="_blank" href="http://gitlab.iwhalecloud.com/CoP/Java-Coding-Specification/-/blob/master/CERT-Standard/QIWC_33.002.1_2019%E6%B5%A9%E9%B2%B8%E7%A7%91%E6%8A%80Java%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83-%E5%AE%89%E5%85%A8%E7%AF%87.pdf">
            
                    
                    安全编码规范（在线版建设中）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.8" >
            
                <span>
            
                    
                    C++开发规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.8.1" data-path="../CPP/Cpp_ReleasedVersion.html">
            
                <a href="../CPP/Cpp_ReleasedVersion.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8.2" data-path="../CPP/Cpp_CERT_ReleasedVersion.html">
            
                <a href="../CPP/Cpp_CERT_ReleasedVersion.html">
            
                    
                    安全编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.9" >
            
                <span>
            
                    
                    JavaScript开发规范
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.9.1" data-path="JavaScript_ES5_ReleasedVersion.html">
            
                <a href="JavaScript_ES5_ReleasedVersion.html">
            
                    
                    ES5规范
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.1.9.2" data-path="JavaScript_ES6_ReleasedVersion.html">
            
                <a href="JavaScript_ES6_ReleasedVersion.html">
            
                    
                    ES6规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.10" >
            
                <span>
            
                    
                    安全规范及规定
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.10.1" data-path="../../security/Security_Redline/Security_Redline_ReleasedVersion.html">
            
                <a href="../../security/Security_Redline/Security_Redline_ReleasedVersion.html">
            
                    
                    产品安全红线管理规定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.2" data-path="../../security/Security_Design/Security_Design_ReleasedVersion.html">
            
                <a href="../../security/Security_Design/Security_Design_ReleasedVersion.html">
            
                    
                    产品设计安全规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.3" data-path="../../security/R&D_Security/R&D_Security_ReleasedVersion.html">
            
                <a href="../../security/R&D_Security/R&D_Security_ReleasedVersion.html">
            
                    
                    产品研发安全规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.4" data-path="../../security/O&M_Security/O&M_Security_ReleasedVersion.html">
            
                <a href="../../security/O&M_Security/O&M_Security_ReleasedVersion.html">
            
                    
                    交付运维安全规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10.5" data-path="../../security/OSS_Management/PG_OSS_Management_ReleasedVersion.html">
            
                <a href="../../security/OSS_Management/PG_OSS_Management_ReleasedVersion.html">
            
                    
                    开源软件管理规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >ES6规范</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x7C7B;&#x578B;"><b>1. </b>&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x5F15;&#x7528;"><b>2. </b>&#x5F15;&#x7528;</a></li><li><span class="title-icon "></span><a href="#&#x5BF9;&#x8C61;"><b>3. </b>&#x5BF9;&#x8C61;</a></li><li><span class="title-icon "></span><a href="#&#x6570;&#x7EC4;"><b>4. </b>&#x6570;&#x7EC4;</a></li><li><span class="title-icon "></span><a href="#&#x89E3;&#x6784;"><b>5. </b>&#x89E3;&#x6784;</a></li><li><span class="title-icon "></span><a href="#&#x5B57;&#x7B26;&#x4E32;"><b>6. </b>&#x5B57;&#x7B26;&#x4E32;</a></li><li><span class="title-icon "></span><a href="#&#x51FD;&#x6570;"><b>7. </b>&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x7BAD;&#x5934;&#x51FD;&#x6570;"><b>8. </b>&#x7BAD;&#x5934;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x6784;&#x9020;&#x51FD;&#x6570;"><b>9. </b>&#x6784;&#x9020;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x6A21;&#x5757;"><b>10. </b>&#x6A21;&#x5757;</a></li><li><span class="title-icon "></span><a href="#&#x8FED;&#x4EE3;&#x5668;&#x548C;&#x751F;&#x6210;&#x5668;"><b>11. </b>&#x8FED;&#x4EE3;&#x5668;&#x548C;&#x751F;&#x6210;&#x5668;</a></li><li><span class="title-icon "></span><a href="#&#x5C5E;&#x6027;"><b>12. </b>&#x5C5E;&#x6027;</a></li><li><span class="title-icon "></span><a href="#&#x53D8;&#x91CF;"><b>13. </b>&#x53D8;&#x91CF;</a></li><li><span class="title-icon "></span><a href="#&#x63D0;&#x5347;"><b>14. </b>&#x63D0;&#x5347;</a></li><li><span class="title-icon "></span><a href="#&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x7B49;&#x53F7;"><b>15. </b>&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x7B49;&#x53F7;</a></li><li><span class="title-icon "></span><a href="#&#x4EE3;&#x7801;&#x5757;"><b>16. </b>&#x4EE3;&#x7801;&#x5757;</a></li><li><span class="title-icon "></span><a href="#&#x6CE8;&#x91CA;"><b>17. </b>&#x6CE8;&#x91CA;</a></li><li><span class="title-icon "></span><a href="#&#x7A7A;&#x767D;"><b>18. </b>&#x7A7A;&#x767D;</a></li><li><span class="title-icon "></span><a href="#&#x9017;&#x53F7;"><b>19. </b>&#x9017;&#x53F7;</a></li><li><span class="title-icon "></span><a href="#&#x5206;&#x53F7;"><b>20. </b>&#x5206;&#x53F7;</a></li><li><span class="title-icon "></span><a href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><b>21. </b>&#x7C7B;&#x578B;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#&#x547D;&#x540D;&#x89C4;&#x5219;"><b>22. </b>&#x547D;&#x540D;&#x89C4;&#x5219;</a></li><li><span class="title-icon "></span><a href="#&#x5B58;&#x53D6;&#x5668;"><b>23. </b>&#x5B58;&#x53D6;&#x5668;</a></li><li><span class="title-icon "></span><a href="#&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;"><b>24. </b>&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5B89;&#x88C5;"><b>24.1. </b>&#x5B89;&#x88C5;</a></li><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;"><b>24.2. </b>&#x4F7F;&#x7528;</a></li><li><span class="title-icon "></span><a href="#&#x53C2;&#x6570;&#x8BF4;&#x660E;"><b>24.3. </b>&#x53C2;&#x6570;&#x8BF4;&#x660E;</a></li><li><span class="title-icon "></span><a href="#&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;cicd&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;"><b>24.4. </b>&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;CI/CD&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;</a></li></ul><li><span class="title-icon "></span><a href="#ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;"><b>25. </b>IDE&#x5DE5;&#x5177;&#x914D;&#x7F6E;</a></li></ul></div><a href="#&#x7C7B;&#x578B;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><p><img src="picture/pg_es6.png" alt="&#x5C01;&#x9762;"></p>
<h1 id="&#x7C7B;&#x578B;"><a name="&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x7C7B;&#x578B;</h1>
<ul>
<li><p><a href="#1.1">1.1</a> <a name="1.1"></a> <strong>&#x57FA;&#x672C;&#x7C7B;&#x578B;</strong>: &#x76F4;&#x63A5;&#x5B58;&#x53D6;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x3002;</p>
<ul>
<li><code>string</code></li>
<li><code>number</code></li>
<li><code>boolean</code></li>
<li><code>null</code></li>
<li><code>undefined</code></li>
</ul>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-number">1</span>;
<span class="hljs-keyword">let</span> bar = foo;

bar = <span class="hljs-number">9</span>;

<span class="hljs-built_in">console</span>.log(foo, bar); <span class="hljs-comment">// =&gt; 1, 9</span>
</code></pre>
</li>
<li><p><a href="#1.2">1.2</a> <a name="1.2"></a> <strong>&#x590D;&#x6742;&#x7C7B;&#x578B;</strong>: &#x901A;&#x8FC7;&#x5F15;&#x7528;&#x7684;&#x65B9;&#x5F0F;&#x5B58;&#x53D6;&#x590D;&#x6742;&#x7C7B;&#x578B;&#x3002;</p>
<ul>
<li><code>object</code></li>
<li><code>array</code></li>
<li><code>function</code></li>
</ul>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = {
  a: <span class="hljs-number">1</span>,
  b: <span class="hljs-number">2</span>,
};
<span class="hljs-keyword">const</span> bar = foo;

bar.a = <span class="hljs-number">9</span>;

<span class="hljs-built_in">console</span>.log(foo.a, bar.a); <span class="hljs-comment">// =&gt; 9, 9</span>
</code></pre>
</li>
</ul>
<h1 id="&#x5F15;&#x7528;"><a name="&#x5F15;&#x7528;" class="anchor-navigation-ex-anchor" href="#&#x5F15;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x5F15;&#x7528;</h1>
<ul>
<li><p><a href="#2.1">2.1</a> <a name="2.1"></a> &#x5BF9;&#x6240;&#x6709;&#x7684;&#x5F15;&#x7528;&#x4F7F;&#x7528; <code>const</code> &#xFF1B;&#x4E0D;&#x8981;&#x4F7F;&#x7528; <code>var</code>&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L108" target="_blank"><code>no-var</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x80FD;&#x786E;&#x4FDD;&#x4F60;&#x65E0;&#x6CD5;&#x5BF9;&#x5F15;&#x7528;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5BFC;&#x81F4;&#x51FA;&#x73B0; bug &#x6216;&#x96BE;&#x4EE5;&#x7406;&#x89E3;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">1</span>;
<span class="hljs-keyword">const</span> b = <span class="hljs-number">2</span>;
</code></pre>
</li>
<li><p><a href="#2.2">2.2</a> <a name="2.2"></a> &#x5982;&#x679C;&#x4F60;&#x4E00;&#x5B9A;&#x9700;&#x8981;&#x53EF;&#x53D8;&#x52A8;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x4F7F;&#x7528; <code>let</code> &#x4EE3;&#x66FF; <code>var</code>&#x3002;<code>const</code>&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x662F;&#x4E0D;&#x5141;&#x8BB8;&#x4FEE;&#x6539;&#x7684;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L56" target="_blank"><code>no-const-assign</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;  <code>let</code> &#x662F;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x800C; <code>var</code> &#x662F;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> count = <span class="hljs-number">1</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
  count += <span class="hljs-number">1</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> count = <span class="hljs-number">1</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
  count += <span class="hljs-number">1</span>;
}
</code></pre>
<p><em>[&#x8BF4;&#x660E;] use the let.</em></p>
</li>
</ul>
<ul>
<li><p><a href="#2.3">2.3</a> <a name="2.3"></a> <code>let</code>&#x548C;<code>const</code>&#x4E0D;&#x5141;&#x8BB8;&#x4E00;&#x6B21;&#x58F0;&#x660E;&#x591A;&#x4E2A;&#x53D8;&#x91CF;/&#x5E38;&#x91CF;&#xFF0C;&#x7528;&#x9017;&#x53F7;&#x9694;&#x5F00;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bar = <span class="hljs-number">1</span>, baz = <span class="hljs-string">&apos;test&apos;</span>;
<span class="hljs-keyword">let</span> a, b;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bar = <span class="hljs-number">1</span>;
<span class="hljs-keyword">const</span> baz = <span class="hljs-string">&apos;test&apos;</span>;
<span class="hljs-keyword">let</span> a;
<span class="hljs-keyword">let</span> b;
</code></pre>
</li>
<li><p><a href="#2.4">2.4</a> <a name="2.4"></a> &#x6CE8;&#x610F; <code>let</code> &#x548C; <code>const</code> &#x90FD;&#x662F;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">{
  <span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>;
  <span class="hljs-keyword">const</span> b = <span class="hljs-number">1</span>;
}
<span class="hljs-built_in">console</span>.log(a); <span class="hljs-comment">// ReferenceError</span>
<span class="hljs-built_in">console</span>.log(b); <span class="hljs-comment">// ReferenceError</span>
</code></pre>
<p><em>[&#x8BF4;&#x660E;] const &#x548C; let &#x53EA;&#x5B58;&#x5728;&#x4E8E;&#x5B83;&#x4EEC;&#x88AB;&#x5B9A;&#x4E49;&#x7684;&#x533A;&#x5757;&#x5185;&#x3002;</em></p>
</li>
</ul>
<h1 id="&#x5BF9;&#x8C61;"><a name="&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x5BF9;&#x8C61;</h1>
<ul>
<li><p><a href="#3.1">3.1</a> <a name="3.1"></a> &#x4F7F;&#x7528;&#x5B57;&#x9762;&#x8BED;&#x6CD5;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L385" target="_blank"><code>no-new-object</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> item = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> item = {};
</code></pre>
</li>
<li><p><a href="#3.2">3.2</a> <a name="3.2"></a> &#x5982;&#x679C;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x4E0B;&#x6267;&#x884C;&#xFF0C;&#x522B;&#x4F7F;&#x7528; <a href="http://es5.github.io/#x7.6.1" target="_blank">&#x4FDD;&#x7559;&#x5B57;</a> &#x4F5C;&#x4E3A;&#x952E;&#x503C;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#x5728; IE8 &#x4E0D;&#x4F1A;&#x8FD0;&#x884C;&#x3002; <a href="https://github.com/airbnb/javascript/issues/61" target="_blank">&#x66F4;&#x591A;&#x4FE1;&#x606F;</a>&#x3002; &#x4F46;&#x5728; ES6 &#x6A21;&#x5757;&#x548C;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x4E2D;&#x4F7F;&#x7528;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> superman = {
  <span class="hljs-keyword">default</span>: { clark: <span class="hljs-string">&apos;kent&apos;</span> },
  private: <span class="hljs-literal">true</span>,
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> superman = {
  defaults: { clark: <span class="hljs-string">&apos;kent&apos;</span> },
  hidden: <span class="hljs-literal">true</span>,
};
</code></pre>
</li>
<li><p><a href="#3.3">3.3</a> <a name="3.3"></a> &#x4F7F;&#x7528;&#x540C;&#x4E49;&#x8BCD;&#x66FF;&#x6362;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x4FDD;&#x7559;&#x5B57;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">const superman = {
  class: &apos;alien&apos;,
};

const superman = {
  klass: &apos;alien&apos;,
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> superman = {
  type: <span class="hljs-string">&apos;alien&apos;</span>,
};
</code></pre>
<p><a name="es6-computed-properties"></a></p>
</li>
<li><p><a href="#3.4">3.4</a> <a name="3.4"></a> &#x521B;&#x5EFA;&#x6709;&#x52A8;&#x6001;&#x5C5E;&#x6027;&#x540D;&#x7684;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x53EF;&#x88AB;&#x8BA1;&#x7B97;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x79F0;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x8BA9;&#x4F60;&#x5728;&#x4E00;&#x4E2A;&#x5730;&#x65B9;&#x5B9A;&#x4E49;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getKey</span>(<span class="hljs-params">k</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`a key named <span class="hljs-subst">${k}</span>`</span>;
}

<span class="hljs-keyword">const</span> obj = {
  id: <span class="hljs-number">5</span>,
  name: <span class="hljs-string">&apos;San Francisco&apos;</span>,
};
obj[getKey(<span class="hljs-string">&apos;enabled&apos;</span>)] = <span class="hljs-literal">true</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getKey</span>(<span class="hljs-params">k</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`a key named <span class="hljs-subst">${k}</span>`</span>;
}

<span class="hljs-keyword">const</span> obj = {
  id: <span class="hljs-number">5</span>,
  name: <span class="hljs-string">&apos;San Francisco&apos;</span>,
&#x3000;[getKey(<span class="hljs-string">&apos;enabled&apos;</span>)]: <span class="hljs-literal">true</span>,
};
</code></pre>
</li>
<li><p><a href="#3.5">3.5</a> <a name="3.5"></a> &#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x503C;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x7B80;&#x5199;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L112" target="_blank">object-shorthand</a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x66F4;&#x77ED;&#x66F4;&#x6709;&#x63CF;&#x8FF0;&#x6027;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> lukeSkywalker = <span class="hljs-string">&apos;Luke Skywalker&apos;</span>;

<span class="hljs-keyword">const</span> obj = {
  lukeSkywalker: lukeSkywalker,
  addValue: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">value</span>) </span>{
    <span class="hljs-keyword">return</span> atom.value + value;
  },
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> lukeSkywalker = <span class="hljs-string">&apos;Luke Skywalker&apos;</span>;

<span class="hljs-keyword">const</span> obj = {
  lukeSkywalker,
  addValue(value) {
    <span class="hljs-keyword">return</span> atom.value + value;
  },
};
</code></pre>
</li>
<li><p><a href="#3.6">3.6</a> <a name="3.6"></a> &#x5982;&#x679C;&#x5BF9;&#x8C61;&#x7684;&#x952E;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x8BF7;&#x4F7F;&#x7528;&#x957F;&#x683C;&#x5F0F;&#x8BED;&#x6CD5;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = {
  <span class="hljs-string">&apos;bar-baz&apos;</span>() {},
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = {
  <span class="hljs-string">&apos;bar-baz&apos;</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{},
};
</code></pre>
</li>
<li><p><a href="#3.7">3.7</a> <a name="3.7"></a> &#x5728;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x58F0;&#x660E;&#x524D;&#x628A;&#x7B80;&#x5199;&#x7684;&#x5C5E;&#x6027;&#x5206;&#x7EC4;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x80FD;&#x6E05;&#x695A;&#x5730;&#x770B;&#x51FA;&#x54EA;&#x4E9B;&#x5C5E;&#x6027;&#x4F7F;&#x7528;&#x4E86;&#x7B80;&#x5199;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> anakinSkywalker = <span class="hljs-string">&apos;Anakin Skywalker&apos;</span>;
<span class="hljs-keyword">const</span> lukeSkywalker = <span class="hljs-string">&apos;Luke Skywalker&apos;</span>;

<span class="hljs-keyword">const</span> obj = {
  episodeOne: <span class="hljs-number">1</span>,
  twoJedisWalkIntoACantina: <span class="hljs-number">2</span>,
  lukeSkywalker,
  episodeThree: <span class="hljs-number">3</span>,
  mayTheFourth: <span class="hljs-number">4</span>,
  anakinSkywalker,
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> anakinSkywalker = <span class="hljs-string">&apos;Anakin Skywalker&apos;</span>;
<span class="hljs-keyword">const</span> lukeSkywalker = <span class="hljs-string">&apos;Luke Skywalker&apos;</span>;

<span class="hljs-keyword">const</span> obj = {
  lukeSkywalker,
  anakinSkywalker,
  episodeOne: <span class="hljs-number">1</span>,
  twoJedisWalkIntoACantina: <span class="hljs-number">2</span>,
  episodeThree: <span class="hljs-number">3</span>,
  mayTheFourth: <span class="hljs-number">4</span>,
};
</code></pre>
</li>
<li><p><a href="#3.8">3.8</a> <a name="3.8"></a> &#x4E0D;&#x5141;&#x8BB8;&#x5728;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x7533;&#x660E;&#x5BF9;&#x8C61;&#x65F6;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7684;&#x952E;&#x540D;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L53" target="_blank"><code>no-dupe-keys</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = {
  bar: <span class="hljs-string">&apos;baz&apos;</span>,
  bar: <span class="hljs-string">&apos;qux&apos;</span>,
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = {
  bar: <span class="hljs-string">&apos;baz&apos;</span>,
  quxx: <span class="hljs-string">&apos;qux&apos;</span>,
};
</code></pre>
</li>
<li><p><a href="#3.9">3.9</a> <a name="3.9"></a> &#x7981;&#x6B62;&#x5C06;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF08;Math&#x548C;JSON)&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/errors.js#L70" target="_blank"><code>no-obj-calls</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> math = <span class="hljs-built_in">Math</span>();
<span class="hljs-keyword">const</span> json = <span class="hljs-built_in">JSON</span>();
<span class="hljs-keyword">const</span> reflect = <span class="hljs-built_in">Reflect</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">area</span>(<span class="hljs-params">r</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.PI * r * r;
}
<span class="hljs-keyword">const</span> object = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-string">&quot;{}&quot;</span>);
<span class="hljs-keyword">const</span> value = <span class="hljs-built_in">Reflect</span>.get({ x: <span class="hljs-number">1</span>, y: <span class="hljs-number">2</span> }, <span class="hljs-string">&quot;x&quot;</span>);
</code></pre>
</li>
<li><p><a href="#3.10">3.10</a> <a name="3.10"></a> &#x7981;&#x6B62;&#x5728;&#x5BF9;&#x8C61;&#x4E2D;&#x4F7F;&#x7528;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L89" target="_blank"><code>no-useless-computed-key</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = { [<span class="hljs-string">&apos;0&apos;</span>]: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> a = { [<span class="hljs-string">&apos;0+1,234&apos;</span>]: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> a = { [<span class="hljs-number">0</span>]: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> a = { [<span class="hljs-string">&apos;x&apos;</span>]: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> a = { [<span class="hljs-string">&apos;x&apos;</span>]() {} };
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> c = { a: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> c = { <span class="hljs-number">0</span>: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> a = { x() {} };
<span class="hljs-keyword">const</span> c = { a: <span class="hljs-number">0</span> };
<span class="hljs-keyword">const</span> c = { <span class="hljs-string">&apos;0+1,234&apos;</span>: <span class="hljs-number">0</span> };
</code></pre>
</li>
<li><p><a href="#3.11">3.11</a> <a name="3.11"></a> &#x53EA;&#x5141;&#x8BB8;&#x5F15;&#x53F7;&#x6807;&#x6CE8;&#x65E0;&#x6548;&#x6807;&#x8BC6;&#x7B26;&#x7684;&#x5C5E;&#x6027;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L425" target="_blank"><code>no-useless-computed-key</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bad = {
  <span class="hljs-string">&apos;foo&apos;</span>: <span class="hljs-number">3</span>,
  <span class="hljs-string">&apos;bar&apos;</span>: <span class="hljs-number">4</span>,
  <span class="hljs-string">&apos;data-blah&apos;</span>: <span class="hljs-number">5</span>,
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> good = {
  foo: <span class="hljs-number">3</span>,
  bar: <span class="hljs-number">4</span>,
  <span class="hljs-string">&apos;data-blah&apos;</span>: <span class="hljs-number">5</span>,
};
</code></pre>
</li>
</ul>
<h1 id="&#x6570;&#x7EC4;"><a name="&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x6570;&#x7EC4;</h1>
<ul>
<li><p><a href="#4.1">4.1</a> <a name="4.1"></a> &#x4F7F;&#x7528;&#x5B57;&#x9762;&#x503C;&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x3002;&#x7981;&#x6B62;&#x4F7F;&#x7528;new&#x521B;&#x5EFA;&#x5305;&#x88C5;&#x5B9E;&#x4F8B;&#xFF0C;&#x5982; new String&#x3001;new Number&#xFF0C;&#x8FD9;&#x6837;&#x4F1A;&#x53D8;&#x6210;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5BF9;&#x5E94;&#x7684;&#x521D;&#x59CB;&#x7C7B;&#x578B;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L210" target="_blank"><code>no-new-wrappers</code></a>  <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L316" target="_blank"><code>no-array-constructor</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = [];
</code></pre>
</li>
<li><p><a href="#4.2">4.2</a> <a name="4.2"></a> &#x5411;&#x6570;&#x7EC4;&#x6DFB;&#x52A0;&#x5143;&#x7D20;&#x65F6;&#x4F7F;&#x7528; Arrary#push &#x66FF;&#x4EE3;&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> someStack = [];

someStack[someStack.length] = <span class="hljs-string">&apos;abracadabra&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> someStack = [];

someStack.push(<span class="hljs-string">&apos;abracadabra&apos;</span>);
</code></pre>
<p><a name="es6-array-spreads"></a></p>
</li>
<li><p><a href="#4.3">4.3</a> <a name="4.3"></a> &#x4F7F;&#x7528;&#x6570;&#x7EC4;&#x5C55;&#x5F00;&#x65B9;&#x6CD5;<code>...</code>&#x6765;&#x62F7;&#x8D1D;&#x6570;&#x7EC4;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> len = items.length;
<span class="hljs-keyword">const</span> itemsCopy = [];
<span class="hljs-keyword">let</span> i;

<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; len; i += <span class="hljs-number">1</span>) {
  itemsCopy[i] = items[i];
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> itemsCopy = [...items];
</code></pre>
</li>
<li><p><a href="#4.4">4.4</a> <a name="4.4"></a> &#x5C06;&#x4E00;&#x4E2A;&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x6210;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C; &#x4F7F;&#x7528;&#x5C55;&#x5F00;&#x65B9;&#x6CD5;<code>...</code>&#x4EE3;&#x66FF;<code>Array.from</code>&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B; good</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">&apos;.foo&apos;</span>);

<span class="hljs-keyword">const</span> nodes = <span class="hljs-built_in">Array</span>.from(foo);
</code></pre>
<p><strong>&#x6B63;&#x4F8B; best</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">&apos;.foo&apos;</span>);

<span class="hljs-keyword">const</span> nodes = [...foo];
</code></pre>
</li>
<li><p><a href="#4.5">4.5</a> <a name="4.5"></a> &#x5728;&#x6570;&#x7EC4;&#x56DE;&#x8C03;&#x65B9;&#x6CD5;&#x4E2D;&#x4F7F;&#x7528; return &#x8BED;&#x53E5;&#x3002; &#x5982;&#x679C;&#x51FD;&#x6570;&#x4F53;&#x7531;&#x4E00;&#x4E2A;&#x8FD4;&#x56DE;&#x65E0;&#x526F;&#x4F5C;&#x7528;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x5355;&#x4E2A;&#x8BED;&#x53E5;&#x7EC4;&#x6210;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x8FD4;&#x56DE;&#x503C;, &#x5177;&#x4F53;&#x67E5;&#x770B;<a href="#8.3">8.3</a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">[[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>], [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>]].reduce((acc, item, index) =&gt; {
  <span class="hljs-keyword">const</span> flatten = acc.concat(item);
  acc[index] = flatten;
});

inbox.filter( msg =&gt; {
  <span class="hljs-keyword">const</span> { subject, author } = msg;
  <span class="hljs-keyword">if</span> (subject === <span class="hljs-string">&apos;Mockingbird&apos;</span>) {
    <span class="hljs-keyword">return</span> author === <span class="hljs-string">&apos;Harper Lee&apos;</span>;
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }
});
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x5728;&#x7B2C;&#x4E00;&#x6B21;&#x8FED;&#x4EE3;&#x540E; <code>acc</code> &#x6CA1;&#x6709;&#x88AB;&#x5B9A;&#x4E49;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">inbox.filter( msg =&gt; {
  <span class="hljs-keyword">const</span> { subject, author } = msg;
  <span class="hljs-keyword">if</span> (subject === <span class="hljs-string">&apos;Mockingbird&apos;</span>) {
    <span class="hljs-keyword">return</span> author === <span class="hljs-string">&apos;Harper Lee&apos;</span>;
  }

  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
});

[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].map(x =&gt; x + <span class="hljs-number">1</span>);
</code></pre>
</li>
</ul>
<h1 id="&#x89E3;&#x6784;"><a name="&#x89E3;&#x6784;" class="anchor-navigation-ex-anchor" href="#&#x89E3;&#x6784;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x89E3;&#x6784;</h1>
<ul>
<li><p><a href="#5.1">5.1</a> <a name="5.1"></a> &#x5728;&#x8BBF;&#x95EE;&#x548C;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x591A;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L134" target="_blank"><code>prefer-destructuring</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x89E3;&#x6784;&#x53EF;&#x4EE5;&#x907F;&#x514D;&#x4E3A;&#x8FD9;&#x4E9B;&#x5C5E;&#x6027;&#x521B;&#x5EFA;&#x4E34;&#x65F6;&#x5F15;&#x7528;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFullName</span>(<span class="hljs-params">user</span>) </span>{
  <span class="hljs-keyword">const</span> firstName = user.firstName;
  <span class="hljs-keyword">const</span> lastName = user.lastName;

  <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${firstName}</span> <span class="hljs-subst">${lastName}</span>`</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B; good</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFullName</span>(<span class="hljs-params">obj</span>) </span>{
  <span class="hljs-keyword">const</span> { firstName, lastName } = obj;
  <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${firstName}</span> <span class="hljs-subst">${lastName}</span>`</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B; best</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFullName</span>(<span class="hljs-params">{ firstName, lastName }</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${firstName}</span> <span class="hljs-subst">${lastName}</span>`</span>;
}
</code></pre>
</li>
<li><p><a href="#5.2">5.2</a> <a name="5.2"></a> &#x5BF9;&#x6570;&#x7EC4;&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L134" target="_blank"><code>prefer-destructuring</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];

<span class="hljs-keyword">const</span> first = arr[<span class="hljs-number">0</span>];
<span class="hljs-keyword">const</span> second = arr[<span class="hljs-number">1</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];

<span class="hljs-keyword">const</span> [first, second] = arr; <span class="hljs-comment">// first = 1  second = 2</span>
<span class="hljs-keyword">const</span> [, first, second] = arr;
</code></pre>
</li>
<li><p><a href="#5.3">5.3</a> <a name="5.3"></a> &#x5BF9;&#x4E8E;&#x591A;&#x4E2A;&#x8FD4;&#x56DE;&#x503C;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x89E3;&#x6784;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6570;&#x7EC4;&#x89E3;&#x6784;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x4F60;&#x53EF;&#x4EE5;&#x968F;&#x65F6;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x6539;&#x53D8;&#x5C5E;&#x6027;&#x7684;&#x987A;&#x5E8F;&#xFF0C;&#x800C;&#x4E0D;&#x7528;&#x4FEE;&#x6539;&#x8C03;&#x7528;&#x65B9;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">processInput</span>(<span class="hljs-params">input</span>) </span>{
  <span class="hljs-comment">// then a miracle occurs</span>
  <span class="hljs-keyword">return</span> [left, right, top, bottom];
}

<span class="hljs-keyword">const</span> [left, __, top] = processInput(input);
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x8C03;&#x7528;&#x65F6;&#x9700;&#x8981;&#x8003;&#x8651;&#x56DE;&#x8C03;&#x6570;&#x636E;&#x7684;&#x987A;&#x5E8F;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">processInput</span>(<span class="hljs-params">input</span>) </span>{
  <span class="hljs-comment">// then a miracle occurs</span>
  <span class="hljs-keyword">return</span> { left, right, top, bottom };
}

<span class="hljs-keyword">const</span> { left, right } = processInput(input);
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x8C03;&#x7528;&#x65F6;&#x53EA;&#x9009;&#x62E9;&#x9700;&#x8981;&#x7684;&#x6570;&#x636E;&#x3002;</em></p>
</li>
</ul>
<h1 id="&#x5B57;&#x7B26;&#x4E32;"><a name="&#x5B57;&#x7B26;&#x4E32;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x5B57;&#x7B26;&#x4E32;</h1>
<ul>
<li><p><a href="#6.1">6.1</a> <a name="6.1"></a> &#x9759;&#x6001;&#x5B57;&#x7B26;&#x4E32;&#x4E00;&#x5F8B;&#x4F7F;&#x7528;&#x5355;&#x5F15;&#x53F7; <code>&apos;&apos;</code> &#x3002;&#xFF08;&#x5982;&#x679C;&#x4E0D;&#x662F;&#x5F15;&#x53F7;&#x5D4C;&#x5957;&#xFF0C;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x53CC;&#x5F15;&#x53F7;&#xFF09;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L529" target="_blank"><code>quotes</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> name = <span class="hljs-string">&quot;Capt. Janeway&quot;</span>;

<span class="hljs-keyword">const</span> name = <span class="hljs-string">`Capt. Janeway`</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x6A21;&#x677F;&#x6587;&#x5B57;&#x5E94;&#x8BE5;&#x5305;&#x542B;&#x63D2;&#x503C;&#x6216;&#x6362;&#x884C;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> name = <span class="hljs-string">&apos;Capt. Janeway&apos;</span>;
</code></pre>
</li>
<li><p><a href="#6.2">6.2</a> <a name="6.2"></a> &#x4F7F;&#x884C;&#x8D85;&#x8FC7;100&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E0D;&#x5E94;&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;&#x8DE8;&#x591A;&#x884C;&#x5199;&#x5165;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#xFF1A;&#x8FC7;&#x5EA6;&#x4F7F;&#x7528;&#x5B57;&#x4E32;&#x8FDE;&#x63A5;&#x7B26;&#x53F7;&#x53EF;&#x80FD;&#x4F1A;&#x5BF9;&#x6027;&#x80FD;&#x9020;&#x6210;&#x5F71;&#x54CD;&#x3002;<a href="http://jsperf.com/ya-string-concat" target="_blank">jsPerf</a> &#x548C; <a href="https://github.com/airbnb/javascript/issues/40" target="_blank">&#x8BA8;&#x8BBA;</a>.</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> errorMessage = <span class="hljs-string">&apos;This is a super long error that was thrown because \
of Batman. When you stop to think about how Batman had anything to do \
with this, you would get nowhere \
fast.&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> errorMessage = <span class="hljs-string">&apos;This is a super long error that was thrown because &apos;</span> +
  <span class="hljs-string">&apos;of Batman. When you stop to think about how Batman had anything to do &apos;</span> +
  <span class="hljs-string">&apos;with this, you would get nowhere fast.&apos;</span>;
<span class="hljs-keyword">const</span> errorMessage = <span class="hljs-string">&apos;This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.&apos;</span>;
</code></pre>
<p><a name="es6-template-literals"></a></p>
</li>
<li><p><a href="#6.3">6.3</a> <a name="6.3"></a> &#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x6A21;&#x677F;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L171" target="_blank">prefer-template</a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;&#x4E3A;&#x60A8;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x53EF;&#x8BFB;&#x7684;&#x3001;&#x7B80;&#x6D01;&#x7684;&#x8BED;&#x6CD5;&#xFF0C;&#x5177;&#x6709;&#x6B63;&#x786E;&#x7684;&#x6362;&#x884C;&#x548C;&#x5B57;&#x7B26;&#x4E32;&#x63D2;&#x503C;&#x7279;&#x6027;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHi</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;How are you, &apos;</span> + name + <span class="hljs-string">&apos;?&apos;</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHi</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> [<span class="hljs-string">&apos;How are you, &apos;</span>, name, <span class="hljs-string">&apos;?&apos;</span>].join();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHi</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`How are you, <span class="hljs-subst">${name}</span>?`</span>;
}
</code></pre>
</li>
<li><p><a href="#6.4">6.4</a> <a name="6.4"></a> &#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x5D4C;&#x5165;&#x8868;&#x8FBE;&#x5F0F;&#x4E24;&#x7AEF;&#x4E0D;&#x8981;&#x5B58;&#x5728;&#x7A7A;&#x683C;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L201" target="_blank">prefer-template</a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-string">`hello, <span class="hljs-subst">${ name}</span>!`</span>;
<span class="hljs-string">`hello, <span class="hljs-subst">${name }</span>!`</span>;
<span class="hljs-string">`hello, <span class="hljs-subst">${ name }</span>!`</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-string">`hello, <span class="hljs-subst">${name}</span>!`</span>;
<span class="hljs-string">`hello, <span class="hljs-subst">${
    name
}</span>!`</span>;
</code></pre>
</li>
<li><p><a href="#6.5">6.5</a> <a name="6.5"></a> &#x4E0D;&#x8981;&#x5728;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x5B57;&#x7B26;: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L277" target="_blank">no-useless-escape</a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x53CD;&#x659C;&#x6760;&#x635F;&#x5BB3;&#x4E86;&#x53EF;&#x8BFB;&#x6027;&#xFF0C;&#x56E0;&#x6B64;&#x53EA;&#x6709;&#x5728;&#x5FC5;&#x8981;&#x7684;&#x65F6;&#x5019;&#x624D;&#x4F1A;&#x51FA;&#x73B0;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;\&apos;this\&apos; \i\s \&quot;quoted\&quot;&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;\&apos;this\&apos; is &quot;quoted&quot;&apos;</span>;
<span class="hljs-keyword">const</span> foo = <span class="hljs-string">`my name is &apos;<span class="hljs-subst">${name}</span>&apos;`</span>;
</code></pre>
</li>
</ul>
<h1 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x51FD;&#x6570;</h1>
<ul>
<li><p><a href="#7.1">7.1</a> <a name="7.1"></a> &#x4F7F;&#x7528;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4EE3;&#x66FF;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x662F;&#x53EF;&#x547D;&#x540D;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4ED6;&#x4EEC;&#x5728;&#x8C03;&#x7528;&#x6808;&#x4E2D;&#x66F4;&#x5BB9;&#x6613;&#x88AB;&#x8BC6;&#x522B;&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4F1A;&#x628A;&#x6574;&#x4E2A;&#x51FD;&#x6570;&#x63D0;&#x5347;&#xFF08;hoisted&#xFF09;&#xFF0C;&#x800C;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x53EA;&#x4F1A;&#x628A;&#x51FD;&#x6570;&#x7684;&#x5F15;&#x7528;&#x53D8;&#x91CF;&#x540D;&#x63D0;&#x5347;&#x3002;&#x8FD9;&#x6761;&#x89C4;&#x5219;&#x4F7F;&#x5F97;<a href="#arrow-functions">&#x7BAD;&#x5934;&#x51FD;&#x6570;</a>&#x53EF;&#x4EE5;&#x53D6;&#x4EE3;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B; good</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> short = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ...</span>
};
<span class="hljs-keyword">const</span> foo = () =&gt; {};
</code></pre>
<p><strong>&#x6B63;&#x4F8B; best</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
}
</code></pre>
</li>
<li><p><a href="#7.2">7.2</a> <a name="7.2"></a> &#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;:</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">(() =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Welcome to the Internet. Please follow me.&apos;</span>);
})();
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F; (IIFE)&#x3002;</em></p>
</li>
<li><p><a href="#7.3">7.3</a> <a name="7.3"></a> &#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x5728;&#x4E00;&#x4E2A;&#x975E;&#x51FD;&#x6570;&#x4EE3;&#x7801;&#x5757;&#xFF08;<code>if</code>&#x3001;<code>while</code> &#x7B49;&#xFF09;&#x4E2D;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x628A;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x8D4B;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;&#x6D4F;&#x89C8;&#x5668;&#x5141;&#x8BB8;&#x4F60;&#x8FD9;&#x4E48;&#x505A;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x7684;&#x89E3;&#x6790;&#x8868;&#x73B0;&#x4E0D;&#x4E00;&#x81F4;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L97" target="_blank"><code>no-inner-declarations</code></a></p>
</li>
<li><p><a href="#7.4">7.4</a> <a name="7.4"></a> <strong>&#x6CE8;&#x610F;:</strong> ECMA-262 &#x628A; <code>block</code> &#x5B9A;&#x4E49;&#x4E3A;&#x4E00;&#x7EC4;&#x8BED;&#x53E5;&#x3002;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E0D;&#x662F;&#x8BED;&#x53E5;&#x3002;<a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97" target="_blank">&#x9605;&#x8BFB; ECMA-262 &#x5173;&#x4E8E;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x8BF4;&#x660E;</a>&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (currentUser) {
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Nope.&apos;</span>);
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> test;
<span class="hljs-keyword">if</span> (currentUser) {
  test = () =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Yup.&apos;</span>);
  };
}
</code></pre>
</li>
<li><p><a href="#7.5">7.5</a> <a name="7.5"></a> &#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x628A;&#x53C2;&#x6570;&#x547D;&#x540D;&#x4E3A; <code>arguments</code>&#x3002;&#x8FD9;&#x5C06;&#x53D6;&#x4EE3;&#x539F;&#x6765;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x7684; <code>arguments</code> &#x5BF9;&#x8C61;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js#L30" target="_blank"><code>no-shadow-restricted-names</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;<code>arguments</code>&#x5BF9;&#x8C61;&#x662F;&#x6240;&#x6709;(&#x975E;&#x7BAD;&#x5934;)&#x51FD;&#x6570;&#x4E2D;&#x90FD;&#x53EF;&#x7528;&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x4E0D;&#x53EF;&#x5F53;&#x505A;&#x53C2;&#x6570;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">nope</span>(<span class="hljs-params">name, options, arguments</span>) </span>{
  <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">yup</span>(<span class="hljs-params">name, options, args</span>) </span>{
  <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><a name="es6-rest"></a></p>
</li>
<li><p><a href="#7.6">7.6</a> <a name="7.6"></a> &#x4E0D;&#x8981;&#x4F7F;&#x7528; <code>arguments</code>&#x3002;&#x53EF;&#x4EE5;&#x9009;&#x62E9; rest &#x8BED;&#x6CD5; <code>...</code> &#x66FF;&#x4EE3;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L161" target="_blank"><code>prefer-rest-params</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x4F7F;&#x7528; <code>...</code> &#x80FD;&#x660E;&#x786E;&#x4F60;&#x8981;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x3002;&#x53E6;&#x5916; rest &#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x771F;&#x6B63;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x800C; <code>arguments</code> &#x662F;&#x4E00;&#x4E2A;&#x7C7B;&#x6570;&#x7EC4;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">concatenateAll</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> args = <span class="hljs-built_in">Array</span>.prototype.slice.call(<span class="hljs-built_in">arguments</span>);
  <span class="hljs-keyword">return</span> args.join(<span class="hljs-string">&apos;&apos;</span>);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">concatenateAll</span>(<span class="hljs-params">...args</span>) </span>{
  <span class="hljs-keyword">return</span> args.join(<span class="hljs-string">&apos;&apos;</span>);
}
</code></pre>
<p><a name="es6-default-parameters"></a></p>
</li>
<li><p><a href="#7.7">7.7</a> <a name="7.7"></a> &#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x7684;&#x53C2;&#x6570;&#x8BED;&#x6CD5;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6539;&#x53D8;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L223" target="_blank"><code>no-param-reassign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleThings</span>(<span class="hljs-params">opts</span>) </span>{
  <span class="hljs-comment">// &#x4E0D;&#xFF01;&#x6211;&#x4EEC;&#x4E0D;&#x5E94;&#x8BE5;&#x6539;&#x53D8;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x3002;</span>
  <span class="hljs-comment">// &#x66F4;&#x52A0;&#x7CDF;&#x7CD5;: &#x5982;&#x679C;&#x53C2;&#x6570; opts &#x662F; false &#x7684;&#x8BDD;&#xFF0C;&#x5B83;&#x5C31;&#x4F1A;&#x88AB;&#x8BBE;&#x5B9A;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</span>
  <span class="hljs-comment">// &#x4F46;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x4F1A;&#x9020;&#x6210;&#x4E00;&#x4E9B; Bugs&#x3002;</span>
  <span class="hljs-comment">//&#xFF08;&#x8BD1;&#x6CE8;&#xFF1A;&#x4F8B;&#x5982;&#x5F53; opts &#x88AB;&#x8D4B;&#x503C;&#x4E3A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;opts &#x4ECD;&#x7136;&#x4F1A;&#x88AB;&#x4E0B;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x8BBE;&#x5B9A;&#x4E3A;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#x3002;&#xFF09;</span>
  opts = opts || {};
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleThings</span>(<span class="hljs-params">opts</span>) </span>{
  <span class="hljs-keyword">if</span> (opts === <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>) {
    opts = {};
  }
  <span class="hljs-comment">// ...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleThings</span>(<span class="hljs-params">opts = {}</span>) </span>{
  <span class="hljs-comment">// ...</span>
}
</code></pre>
</li>
<li><p><a href="#7.8">7.8</a> <a name="7.8"></a> &#x76F4;&#x63A5;&#x7ED9;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x8D4B;&#x503C;&#x65F6;&#x9700;&#x8981;&#x907F;&#x514D;&#x526F;&#x4F5C;&#x7528;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x5F88;&#x5BB9;&#x6613;&#x6DF7;&#x6DC6;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> b = <span class="hljs-number">1</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">count</span>(<span class="hljs-params">a = b++</span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
}
count();  <span class="hljs-comment">// 1</span>
count();  <span class="hljs-comment">// 2</span>
count(<span class="hljs-number">3</span>); <span class="hljs-comment">// 3</span>
count();  <span class="hljs-comment">// 3</span>
</code></pre>
</li>
<li><p><a href="#7.9">7.9</a> <a name="7.9"></a> &#x5728;&#x51FD;&#x6570;&#x4E2D;&#x6709;&#x5206;&#x652F;&#x65F6;&#xFF0C;&#x4FDD;&#x8BC1;&#x6240;&#x6709;&#x7684;return &#x8BED;&#x53E5;&#x5FC5;&#x987B;&#x6307;&#x5B9A;&#x8FD4;&#x56DE;&#x503C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L27" target="_blank"><code>consistent-return</code></a>  <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L282" target="_blank"><code>no-useless-return</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params">condition</span>) </span>{
  <span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
  <span class="hljs-keyword">return</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params">condition</span>) </span>{
  <span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doSomething</span>(<span class="hljs-params">condition</span>) </span>{
  <span class="hljs-keyword">if</span> (condition) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">if</span> (!(<span class="hljs-keyword">this</span> <span class="hljs-keyword">instanceof</span> Foo)) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Foo();
  }

  <span class="hljs-keyword">this</span>.a = <span class="hljs-number">0</span>;
}
</code></pre>
</li>
<li><p><a href="#7.10">7.10</a> <a name="7.10"></a> &#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x8981;&#x6709; return &#x8BED;&#x53E5;&#x3002;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x5FC5;&#x987B;&#x6700;&#x7EC8;&#x6709;<code>return</code>&#x8BED;&#x53E5;&#x3002; eslint: <a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L7" target="_blank"><code>array-callback-return</code></a></p>
<ul>
<li><code>Array.from</code></li>
<li><code>Array.prototype.every</code></li>
<li><code>Array.prototype.filter</code></li>
<li><code>Array.prototype.find</code></li>
<li><code>Array.prototype.findIndex</code></li>
<li><code>Array.prototype.map</code></li>
<li><code>Array.prototype.reduce</code></li>
<li><code>Array.prototype.reduceRight</code></li>
<li><code>Array.prototype.some</code></li>
<li><code>Array.prototype.sort</code></li>
</ul>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> indexMap = myArray.reduce(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">memo, item, index</span>) </span>{
  memo[item] = index;
}, {});

<span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">Array</span>.from(nodes, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">node</span>) </span>{
  <span class="hljs-keyword">if</span> (node.tagName === <span class="hljs-string">&quot;DIV&quot;</span>) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
});

<span class="hljs-keyword">const</span> bar = foo.filter(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">if</span> (x) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
  <span class="hljs-keyword">return</span>;
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> indexMap = myArray.reduce((memo, item, index) =&gt; {
  memo[item] = index;
  <span class="hljs-keyword">return</span> memo;
}, {});

<span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">Array</span>.from(nodes, node =&gt; {
  <span class="hljs-keyword">if</span> (node.tagName === <span class="hljs-string">&apos;DIV&apos;</span>) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
});

<span class="hljs-keyword">const</span> bar = foo.map(node =&gt; node.getAttribute(<span class="hljs-string">&apos;id&apos;</span>));
</code></pre>
</li>
<li><p><a href="#7.11">7.11</a> <a name="7.11"></a> &#x8C03;&#x7528;&#x65E0;&#x53C2;&#x6784;&#x9020;&#x51FD;&#x6570;&#x65F6;&#x5FC5;&#x987B;&#x5E26;&#x62EC;&#x53F7;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L295" target="_blank"><code>new-parens</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = <span class="hljs-keyword">new</span> Person;
<span class="hljs-keyword">const</span> person = <span class="hljs-keyword">new</span> (Person);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = <span class="hljs-keyword">new</span> Person();
<span class="hljs-keyword">const</span> person = <span class="hljs-keyword">new</span> (Person)();
</code></pre>
</li>
<li><p><a href="#7.12">7.12</a> <a name="7.12"></a> &#x51FD;&#x6570;&#x7B7E;&#x540D;&#x4E2D;&#x7684;&#x95F4;&#x8DDD;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js/#L471" target="_blank"><code>space-before-function-paren</code></a>  <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js/#L466" target="_blank"><code>space-before-blocks</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x4E00;&#x81F4;&#x6027;&#x5F88;&#x597D;&#xFF0C;&#x5728;&#x5220;&#x9664;&#x6216;&#x6DFB;&#x52A0;&#x540D;&#x79F0;&#x65F6;&#x4E0D;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x6216;&#x5220;&#x9664;&#x7A7A;&#x683C;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{};
<span class="hljs-keyword">const</span> g = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{};
<span class="hljs-keyword">const</span> h = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
<span class="hljs-keyword">const</span> y = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">a</span>(<span class="hljs-params"></span>) </span>{};
</code></pre>
</li>
<li><p><a href="#7.13">7.13</a> <a name="7.13"></a> &#x4E0D;&#x8981;&#x53D8;&#x5F02;&#x53C2;&#x6570;&#x548C;&#x518D;&#x5206;&#x914D;&#x53C2;&#x6570;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js/#L187" target="_blank"><code>no-param-reassign</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x5C06;&#x4F20;&#x5165;&#x7684;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x53EF;&#x80FD;&#x4F1A;&#x5728;&#x539F;&#x59CB;&#x8C03;&#x7528;&#x7A0B;&#x5E8F;&#x4E2D;&#x9020;&#x6210;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x53D8;&#x91CF;&#x526F;&#x4F5C;&#x7528;&#x3002;&#x91CD;&#x65B0;&#x5206;&#x914D;&#x53C2;&#x6570;&#x4F1A;&#x5BFC;&#x81F4;&#x610F;&#x5916;&#x7684;&#x884C;&#x4E3A;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params">obj</span>) </span>{
  obj.key = <span class="hljs-number">1</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params">a</span>) </span>{
  a = <span class="hljs-number">1</span>;
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f2</span>(<span class="hljs-params">a</span>) </span>{
  <span class="hljs-keyword">if</span> (!a) { a = <span class="hljs-number">1</span>; }
  <span class="hljs-comment">// ...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f3</span>(<span class="hljs-params">a</span>) </span>{
  <span class="hljs-keyword">const</span> b = a || <span class="hljs-number">1</span>;
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f4</span>(<span class="hljs-params">a = 1</span>) </span>{
  <span class="hljs-comment">// ...</span>
}
</code></pre>
</li>
<li><p><a href="#7.14">7.14</a> <a name="7.14"></a> <code>Generator</code> &#x51FD;&#x6570;&#x662F; ES6 &#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x79CD;&#x5F02;&#x6B65;&#x7F16;&#x7A0B;&#x89E3;&#x51B3;&#x65B9;&#x6848;.</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;<code>Generator</code>&#xFF1F;&#x4E3A;&#x4E86;&#x89E3;&#x51B3;javascript&#x5F02;&#x6B65;&#x56DE;&#x8C03;&#x5C42;&#x5C42;&#x5D4C;&#x5957;&#x7684;&#x95EE;&#x9898;&#xFF0C;<code>Generator</code> &#x51FD;&#x6570;&#x63D0;&#x4F9B;&#x4E86;&#x5F02;&#x6B65;&#x7F16;&#x7A0B;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#x4ED6;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x7279;&#x5F81;&#xFF1A;</p>
</blockquote>
<ul>
<li><code>function</code>&#x5173;&#x952E;&#x5B57;&#x540E;&#x9762;&#x4F1A;&#x5E26;&#x4E00;&#x4E2A;<code>*</code>&#x53F7;;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x4F1A;&#x4F7F;&#x7528;<code>yield</code>&#x8868;&#x8FBE;&#x5F0F;</li>
<li><code>Generator</code>&#x51FD;&#x6570;&#x662F;&#x5206;&#x6BB5;&#x6267;&#x884C;&#x7684;&#xFF0C;<code>yield</code>&#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x6682;&#x505C;&#x6267;&#x884C;&#x7684;&#x6807;&#x8BB0;&#xFF0C;&#x800C;<code>next</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x6062;&#x590D;&#x6267;&#x884C;</li>
</ul>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>* <span class="hljs-title">helloWorldGenerator</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">yield</span> <span class="hljs-string">&apos;hello&apos;</span>;
  <span class="hljs-keyword">yield</span> <span class="hljs-string">&apos;world&apos;</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;ending&apos;</span>;
}
<span class="hljs-keyword">const</span> hw = helloWorldGenerator();

hw.next();
<span class="hljs-comment">// { value: &apos;hello&apos;, done: false }</span>

hw.next();
<span class="hljs-comment">// { value: &apos;world&apos;, done: false }</span>

hw.next();
<span class="hljs-comment">// { value: &apos;ending&apos;, done: true }</span>

hw.next();
<span class="hljs-comment">// { value: undefined, done: true }</span>
</code></pre>
</li>
<li><p><a href="#7.15">7.15</a> <a name="7.15"></a> <code>Generator</code> &#x51FD;&#x6570;&#x5185;&#x4E00;&#x5B9A;&#x8981;&#x6709;<code>yield</code>&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L176" target="_blank"><code>require-yield</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>* <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>* <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">yield</span> <span class="hljs-number">5</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;
}
</code></pre>
</li>
</ul>
<h1 id="&#x7BAD;&#x5934;&#x51FD;&#x6570;"><a name="&#x7BAD;&#x5934;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x7BAD;&#x5934;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>8. &#x7BAD;&#x5934;&#x51FD;&#x6570;</h1>
<ul>
<li><p><a href="#8.1">8.1</a> <a name="8.1"></a> &#x5F53;&#x4F60;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;&#x6216;&#x4F20;&#x9012;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#xFF09;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7B26;&#x53F7;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x521B;&#x9020;&#x4E86;&#x65B0;&#x7684;&#x4E00;&#x4E2A; <code>this</code> &#x6267;&#x884C;&#x73AF;&#x5883;&#xFF08;&#x8BD1;&#x6CE8;&#xFF1A;&#x53C2;&#x8003; <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions" target="_blank">Arrow functions - JavaScript | MDN</a> &#x548C; <a href="http://toddmotto.com/es6-arrow-functions-syntaxes-and-lexical-scoping/" target="_blank">ES6 arrow functions, syntax and lexical scoping</a>&#xFF09;&#xFF0C;&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#x90FD;&#x80FD;&#x6EE1;&#x8DB3;&#x4F60;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x800C;&#x4E14;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x66F4;&#x4E3A;&#x7B80;&#x6D01;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].map(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">const</span> y = x + <span class="hljs-number">1</span>;
  <span class="hljs-keyword">return</span> x * y;
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B; good</strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].map(x =&gt; {
  <span class="hljs-keyword">const</span> y = x + <span class="hljs-number">1</span>;
  <span class="hljs-keyword">return</span> x * y;
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B; best</strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].map(x =&gt; x * (x + <span class="hljs-number">1</span>));
</code></pre>
</li>
<li><p><a href="#8.2">8.2</a> <a name="8.2"></a> &#x8981;&#x6C42;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x56DE;&#x8C03;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L120" target="_blank"><code>prefer-arrow-callback</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x81EA;&#x52A8;&#x7ED1;&#x5B9A;&#x5230;&#x5176;&#x5468;&#x56F4;&#x4F5C;&#x7528;&#x57DF;/&#x4E0A;&#x4E0B;&#x6587;&#xFF0C;&#x53EF;&#x4EE5;&#x66FF;&#x4EE3;&#x663E;&#x5F0F;&#x7ED1;&#x5B9A;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;</p>
</blockquote>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].reduce((total, n) =&gt; {
  <span class="hljs-keyword">return</span> total + n;
}, <span class="hljs-number">0</span>);
</code></pre>
</li>
<li><p><a href="#8.3">8.3</a> <a name="8.3"></a> &#x5982;&#x679C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x9002;&#x5408;&#x7528;&#x4E00;&#x884C;&#x5199;&#x51FA;&#x5E76;&#x4E14;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x90A3;&#x5C31;&#x628A;&#x82B1;&#x62EC;&#x53F7;&#x3001;&#x5706;&#x62EC;&#x53F7;&#x548C; <code>return</code> &#x90FD;&#x7701;&#x7565;&#x6389;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x662F;&#xFF0C;&#x90A3;&#x5C31;&#x4E0D;&#x8981;&#x7701;&#x7565;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L23" target="_blank"><code>arrow-parens</code></a>&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L17" target="_blank"><code>arrow-body-style</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8BED;&#x6CD5;&#x7CD6;&#x3002;&#x591A;&#x4E2A;&#x51FD;&#x6570;&#x88AB;&#x94FE;&#x63A5;&#x5728;&#x4E00;&#x8D77;&#x65F6;&#xFF0C;&#x63D0;&#x9AD8;&#x53EF;&#x8BFB;&#x6027;&#x3002;</p>
<p>&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x4E0D;&#xFF1F;&#x5F53;&#x4F60;&#x6253;&#x7B97;&#x56DE;&#x4F20;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x65F6;&#x5019;&#x3002;</p>
</blockquote>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].map(x =&gt; x * x);

[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].reduce((total, n) =&gt; total + n, <span class="hljs-number">0</span>);

[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].map(x =&gt; (
  {
    x: x + <span class="hljs-number">1</span>,
  }
));
</code></pre>
</li>
</ul>
<h1 id="&#x6784;&#x9020;&#x51FD;&#x6570;"><a name="&#x6784;&#x9020;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x6784;&#x9020;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>9. &#x6784;&#x9020;&#x51FD;&#x6570;</h1>
<ul>
<li><p><a href="#9.1">9.1</a> <a name="9.1"></a> &#x603B;&#x662F;&#x4F7F;&#x7528; <code>class</code>&#x3002;&#x907F;&#x514D;&#x76F4;&#x63A5;&#x64CD;&#x4F5C; <code>prototype</code> &#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;? &#x56E0;&#x4E3A; <code>class</code> &#x8BED;&#x6CD5;&#x66F4;&#x4E3A;&#x7B80;&#x6D01;&#x66F4;&#x6613;&#x8BFB;&#x3002;ES6&#x7684;&#x7C7B;class&#x53EA;&#x662F;&#x4E00;&#x4E2A;&#x8BED;&#x6CD5;&#x7CD6;&#xFF0C;&#x5B8C;&#x5168;&#x53EF;&#x4EE5;&#x770B;&#x4F5C;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x53E6;&#x4E00;&#x79CD;&#x5199;&#x6CD5;&#x3002;&#x65B0;&#x7684;class&#x5199;&#x6CD5;&#x53EA;&#x662F;&#x8BA9;&#x5BF9;&#x8C61;&#x539F;&#x578B;&#x7684;&#x5199;&#x6CD5;&#x66F4;&#x52A0;&#x6E05;&#x6670;&#x3001;&#x66F4;&#x50CF;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7F16;&#x7A0B;&#x7684;&#x8BED;&#x6CD5;&#x800C;&#x5DF2;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Queue</span>(<span class="hljs-params">contents = []</span>) </span>{
  <span class="hljs-keyword">this</span>._queue = [...contents];
}
Queue.prototype.pop = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> value = <span class="hljs-keyword">this</span>._queue[<span class="hljs-number">0</span>];
  <span class="hljs-keyword">this</span>._queue.splice(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>);
  <span class="hljs-keyword">return</span> value;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Queue</span> </span>{
  <span class="hljs-keyword">constructor</span>(contents = []) {
    <span class="hljs-keyword">this</span>._queue = [...contents];
  }

  pop() {
    <span class="hljs-keyword">const</span> value = <span class="hljs-keyword">this</span>._queue[<span class="hljs-number">0</span>];
    <span class="hljs-keyword">this</span>._queue.splice(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>);
    <span class="hljs-keyword">return</span> value;
  }
}
</code></pre>
</li>
<li><p><a href="#9.2">9.2</a> <a name="9.2"></a> &#x4F7F;&#x7528; <code>extends</code> &#x7EE7;&#x627F;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A; <code>extends</code> &#x662F;&#x4E00;&#x4E2A;&#x5185;&#x5EFA;&#x7684;&#x539F;&#x578B;&#x7EE7;&#x627F;&#x65B9;&#x6CD5;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x5728;&#x4E0D;&#x7834;&#x574F; instanceof &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x7EE7;&#x627F;&#x539F;&#x578B;&#x529F;&#x80FD;&#x3002;&#x8FD9;&#x6BD4;ES5&#x7684;&#x901A;&#x8FC7;&#x4FEE;&#x6539;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#xFF0C;&#x8981;&#x6E05;&#x6670;&#x548C;&#x65B9;&#x4FBF;&#x5F88;&#x591A;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> inherits = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;inherits&apos;</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">PeekableQueue</span>(<span class="hljs-params">contents</span>) </span>{
  Queue.apply(<span class="hljs-keyword">this</span>, contents);
}
inherits(PeekableQueue, Queue);
PeekableQueue.prototype.peek = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._queue[<span class="hljs-number">0</span>];
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PeekableQueue</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Queue</span> </span>{
  peek() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._queue[<span class="hljs-number">0</span>];
  }
}
</code></pre>
</li>
<li><p><a href="#9.3">9.3</a> <a name="9.3"></a> &#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE; <code>this</code> &#x6765;&#x4F9B;&#x5176;&#x5185;&#x90E8;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">Jedi.prototype.jump = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.jumping = <span class="hljs-literal">true</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
};

Jedi.prototype.setHeight = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">height</span>) </span>{
  <span class="hljs-keyword">this</span>.height = height;
};

<span class="hljs-keyword">const</span> luke = <span class="hljs-keyword">new</span> Jedi();
luke.jump(); <span class="hljs-comment">// =&gt; true</span>
luke.setHeight(<span class="hljs-number">20</span>); <span class="hljs-comment">// =&gt; undefined</span>
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Jedi</span> </span>{
  jump() {
    <span class="hljs-keyword">this</span>.jumping = <span class="hljs-literal">true</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
  }

  setHeight(height) {
    <span class="hljs-keyword">this</span>.height = height;
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
  }
}

<span class="hljs-keyword">const</span> luke = <span class="hljs-keyword">new</span> Jedi();

luke.jump()
  .setHeight(<span class="hljs-number">20</span>);
</code></pre>
</li>
<li><p><a href="#9.4">9.4</a> <a name="9.4"></a> &#x53EF;&#x4EE5;&#x5199;&#x4E00;&#x4E2A;&#x81EA;&#x5B9A;&#x4E49;&#x7684; <code>toString()</code> &#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x8981;&#x786E;&#x4FDD;&#x5B83;&#x80FD;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#x5E76;&#x4E14;&#x4E0D;&#x4F1A;&#x5F15;&#x8D77;&#x526F;&#x4F5C;&#x7528;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Jedi</span> </span>{
  <span class="hljs-keyword">constructor</span>(options = {}) {
    <span class="hljs-keyword">this</span>.name = options.name || <span class="hljs-string">&apos;no name&apos;</span>;
  }

  getName() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
  }

  toString() {
    <span class="hljs-keyword">return</span> <span class="hljs-string">`Jedi - <span class="hljs-subst">${this.getName()}</span>`</span>;
  }
}
</code></pre>
</li>
<li><p><a href="#9.5">9.5</a> <a name="9.5"></a> &#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#x7981;&#x6B62;&#x5728;<code>super()</code>&#x8C03;&#x7528;&#x4E4B;&#x524D;&#x4F7F;&#x7528;<code>this</code>&#x6216;<code>super</code>&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L84" target="_blank"><code>no-this-before-super</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">B</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-keyword">this</span>.foo();
    <span class="hljs-keyword">super</span>();
  }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">B</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-keyword">super</span>.foo();
    <span class="hljs-keyword">super</span>();
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-keyword">this</span>.a = <span class="hljs-number">0</span>;
  }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">B</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-keyword">super</span>();
    <span class="hljs-keyword">this</span>.a = <span class="hljs-number">0</span>;
  }
}
</code></pre>
</li>
<li><p><a href="#9.6">9.6</a> <a name="9.6"></a> &#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x7C7B;&#xFF0C;&#x5219;&#x7C7B;&#x5177;&#x6709;&#x9ED8;&#x8BA4;&#x7684;&#x6784;&#x9020;&#x5668;&#x3002; &#x4E00;&#x4E2A;&#x7A7A;&#x7684;&#x6784;&#x9020;&#x5668;&#x6216;&#x662F;&#x4E00;&#x4E2A;&#x4EE3;&#x8868;&#x7236;&#x7C7B;&#x7684;&#x51FD;&#x6570;&#x662F;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x7684;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L94" target="_blank"><code>no-useless-constructor</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;es6&#x4E3A;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x7C7B;&#x63D0;&#x4F9B;&#x4E86;&#x9ED8;&#x8BA4;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x7A7A;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6216;&#x53EA;&#x662F;&#x7B80;&#x5355;&#x7684;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x8FD9;&#x6837;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Jedi</span> </span>{
  <span class="hljs-keyword">constructor</span>() {}

  getName() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
  }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rey</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Jedi</span> </span>{
  <span class="hljs-keyword">constructor</span>(...args) {
    <span class="hljs-keyword">super</span>(...args);
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rey</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Jedi</span> </span>{
  <span class="hljs-keyword">constructor</span>(...args) {
    <span class="hljs-keyword">super</span>(...args);
    <span class="hljs-keyword">this</span>.name = <span class="hljs-string">&apos;Rey&apos;</span>;
  }
}
</code></pre>
</li>
<li><p><a href="#9.7">9.7</a> <a name="9.7"></a> &#x6784;&#x9020;&#x51FD;&#x6570;&#x7C7B;&#x6210;&#x5458;&#x4E2D;&#x4E0D;&#x5141;&#x8BB8;&#x51FA;&#x73B0;&#x91CD;&#x590D;&#x540D;&#x79F0;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L60" target="_blank"><code>no-dupe-class-members</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  bar() {}
  bar() {}
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  bar() {}
  get bar() {}
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  <span class="hljs-keyword">static</span> bar() {}
  <span class="hljs-keyword">static</span> bar() {}
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  bar() {}
  qux() {}
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  get bar() {}
  set bar(value) {}
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  <span class="hljs-keyword">static</span> bar() {}
  bar() {}
}
</code></pre>
</li>
</ul>
<h1 id="&#x6A21;&#x5757;"><a name="&#x6A21;&#x5757;" class="anchor-navigation-ex-anchor" href="#&#x6A21;&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>10. &#x6A21;&#x5757;</h1>
<ul>
<li><p><a href="#10.1">10.1</a> <a name="10.1"></a> &#x603B;&#x662F;&#x4F7F;&#x7528;&#x6A21;&#x7EC4; (<code>import</code>/<code>export</code>) &#x800C;&#x4E0D;&#x662F;&#x5176;&#x4ED6;&#x975E;&#x6807;&#x51C6;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x6A21;&#x5757;&#x5C31;&#x662F;&#x672A;&#x6765;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x8FC8;&#x5411;&#x672A;&#x6765;&#x5427;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> AirbnbStyleGuide = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>);
<span class="hljs-built_in">module</span>.exports = AirbnbStyleGuide.es6;
</code></pre>
<p><strong>&#x6B63;&#x4F8B; good</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> AirbnbStyleGuide <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> AirbnbStyleGuide.es6;
</code></pre>
<p><strong>&#x6B63;&#x4F8B; best</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { es6 } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> es6;
</code></pre>
</li>
<li><p><a href="#10.2">10.2</a> <a name="10.2"></a> &#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x901A;&#x914D;&#x7B26;&#x5BFC;&#x5165;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x6837;&#x80FD;&#x786E;&#x4FDD;&#x4F60;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4; export&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> AirbnbStyleGuide <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x4E0D;&#x62A5;&#x9519;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> AirbnbStyleGuide <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>;
</code></pre>
</li>
<li><p><a href="#10.3">10.3</a> <a name="10.3"></a>&#x4E0D;&#x8981;&#x4ECE; import &#x4E2D;&#x76F4;&#x63A5; export&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x867D;&#x7136;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x7B80;&#x6D01;&#x660E;&#x4E86;&#xFF0C;&#x4F46;&#x8BA9; import &#x548C; export &#x5404;&#x53F8;&#x5176;&#x804C;&#x8BA9;&#x4E8B;&#x60C5;&#x80FD;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> { es6 <span class="hljs-keyword">as</span> <span class="hljs-keyword">default</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./airbnbStyleGuide&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { es6 } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> es6;
</code></pre>
</li>
<li><p><a href="#10.4">10.4</a> <a name="10.4"></a>&#x786E;&#x4FDD;<code>import</code>&#x548C;<code>export</code>&#x547D;&#x540D;&#x5339;&#x914D;&#x3002;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L35" target="_blank"><code>import/named</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// ./foo.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&quot;I&apos;m so foo&quot;</span>;

<span class="hljs-comment">// ./baz.js</span>
<span class="hljs-keyword">import</span> { notFoo } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// ./foo.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&quot;I&apos;m so foo&quot;</span>;

<span class="hljs-comment">// ./bar.js</span>
<span class="hljs-keyword">import</span> { foo } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>
</code></pre>
</li>
<li><p><a href="#10.5">10.5</a> <a name="10.5"></a>&#x6A21;&#x5757;&#x5BFC;&#x5165;&#x987A;&#x5E8F;&#x4F18;&#x5148;&#x7EA7;&#x6CE8;&#x610F;&#x3002;&#x5E76;&#x4E14;<code>import</code>&#x4F18;&#x5148;&#x7EA7;&#x4E00;&#x5B9A;&#x9AD8;&#x4E8E;<code>require</code>&#x3002;&#x6A21;&#x5757;&#x5BFC;&#x5165;&#x6309;&#x7167;&#x4EE5;&#x4E0B;&#x987A;&#x5E8F;&#xFF1A;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L144" target="_blank"><code>import/order</code></a></p>
<ul>
<li>node&#x6A21;&#x5757;(fs&#x7B49;)</li>
<li>&#x5916;&#x90E8;&#x6A21;&#x5757;(lodash&#x7B49;)</li>
<li>&#x5168;&#x5C40;&#x6A21;&#x5757;</li>
<li>&#x7236;&#x76EE;&#x5F55;&#x6A21;&#x5757;</li>
<li>&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x6A21;&#x5757;</li>
</ul>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;lodash&apos;</span>;
<span class="hljs-keyword">import</span> path <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;path&apos;</span>; <span class="hljs-comment">// `path` import should occur before import of `lodash`</span>

<span class="hljs-comment">// -----</span>

<span class="hljs-keyword">const</span> _ = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;lodash&apos;</span>);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>); <span class="hljs-comment">// `path` import should occur before import of `lodash`</span>

<span class="hljs-comment">// -----</span>

<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">import</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>; <span class="hljs-comment">// `import` statements must be before `require` statement</span>
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { es6 } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./AirbnbStyleGuide&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> es6;

<span class="hljs-keyword">import</span> path <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;path&apos;</span>;
<span class="hljs-keyword">import</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;lodash&apos;</span>;

<span class="hljs-comment">// -----</span>

<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">const</span> _ = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;lodash&apos;</span>);

<span class="hljs-comment">// -----</span>

<span class="hljs-comment">// Allowed as &#x300;`babel-register` is not assigned.</span>
<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;babel-register&apos;</span>);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);

<span class="hljs-comment">// -----</span>

<span class="hljs-comment">// Allowed as `import` must be before `require`</span>
<span class="hljs-keyword">import</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>;
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
</code></pre>
</li>
<li><p><a href="#10.6">10.6</a> <a name="10.6"></a>&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x4EC5;&#x6709;&#x4E00;&#x4E2A;&#x5BFC;&#x51FA;&#xFF0C;&#x8BF7;&#x52A0;&#x4E0A;<code>export default</code>&#x3002;&#x540C;&#x6837;&#x7684;&#xFF0C;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5185;&#x53EA;&#x80FD;&#x51FA;&#x73B0;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;<code>export default</code>&#x3002;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L155" target="_blank"><code>import/prefer-default-export</code></a> <a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L55" target="_blank"><code>import/export</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// example1</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;bar&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-string">&apos;bar&apos;</span>;

<span class="hljs-comment">// example2</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;bar&apos;</span>;

<span class="hljs-comment">// example3</span>
<span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;bar&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> { foo, bar }

<span class="hljs-comment">// example4</span>
<span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">export</span> { foo <span class="hljs-keyword">as</span> <span class="hljs-keyword">default</span> }
</code></pre>
</li>
<li><p><a href="#10.7">10.7</a> <a name="10.7"></a>&#x7981;&#x6B62;&#x4F7F;&#x7528;<code>default</code>&#x4F5C;&#x4E3A;&#x5BFC;&#x5165;&#x53D8;&#x91CF;&#x540D;&#xFF0C;&#x56E0;&#x4E3A;&#x4F1A;&#x4E0E;<code>export default</code>&#x51B2;&#x7A81;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x3002;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L206" target="_blank"><code>no-named-default</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// foo.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;baz&apos;</span>;

<span class="hljs-keyword">import</span> { <span class="hljs-keyword">default</span> <span class="hljs-keyword">as</span> foo } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo.js&apos;</span>;
<span class="hljs-keyword">import</span> { <span class="hljs-keyword">default</span> <span class="hljs-keyword">as</span> foo, bar } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo.js&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// foo.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;baz&apos;</span>;

<span class="hljs-keyword">import</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo.js&apos;</span>;
<span class="hljs-keyword">import</span> foo, { bar } <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo.js&apos;</span>;
</code></pre>
</li>
<li><p><a href="#10.8">10.8</a> <a name="10.8"></a>&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x5BFC;&#x5165;&#x3002;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L170" target="_blank"><code>import/no-absolute-path</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> f <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;/foo&apos;</span>;
<span class="hljs-keyword">import</span> f <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;/some/path&apos;</span>;

<span class="hljs-keyword">const</span> f = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;/foo&apos;</span>);
<span class="hljs-keyword">const</span> f = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;/some/path&apos;</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;lodash&apos;</span>;
<span class="hljs-keyword">import</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">import</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>;

<span class="hljs-keyword">const</span> _ = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;lodash&apos;</span>);
<span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;foo&apos;</span>);
<span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./foo&apos;</span>);
</code></pre>
</li>
<li><p><a href="#10.9">10.9</a> <a name="10.9"></a>&#x7981;&#x6B62;&#x4F7F;&#x7528;<code>AMD</code> <code>require/define</code>&#x3002;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js/#L100" target="_blank"><code>import/no-amd</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;ES6&#x5DF2;&#x7ECF;&#x5177;&#x5907;&#x6A21;&#x5757;&#x5316;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x518D;&#x4F7F;&#x7528;<code>AMD</code>&#x89C4;&#x8303;&#x4E86;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">define([<span class="hljs-string">&quot;a&quot;</span>, <span class="hljs-string">&quot;b&quot;</span>], <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">a, b</span>) </span>{ <span class="hljs-comment">/* ... */</span> });

<span class="hljs-built_in">require</span>([<span class="hljs-string">&quot;b&quot;</span>, <span class="hljs-string">&quot;c&quot;</span>], <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">b, c</span>) </span>{ <span class="hljs-comment">/* ... */</span> });
</code></pre>
</li>
<li><p><a href="#10.10">10.10</a> <a name="10.10"></a>&#x7981;&#x6B62;&#x5728; <code>import</code> &#x548C; <code>export</code> &#x548C;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x65F6;&#x5C06;&#x5F15;&#x7528;&#x91CD;&#x547D;&#x540D;&#x4E3A;&#x76F8;&#x540C;&#x7684;&#x540D;&#x5B57;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L99" target="_blank"><code>no-useless-rename</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { foo <span class="hljs-keyword">as</span> foo } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;bar&quot;</span>;

<span class="hljs-keyword">export</span> { foo <span class="hljs-keyword">as</span> foo };
<span class="hljs-keyword">export</span> { foo <span class="hljs-keyword">as</span> foo } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;bar&quot;</span>;

<span class="hljs-keyword">let</span> { foo: foo } = bar;
<span class="hljs-keyword">let</span> { <span class="hljs-string">&apos;foo&apos;</span>: foo } = bar;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">{ bar: bar }</span>) </span>{}
({ foo: foo }) =&gt; {}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;foo&quot;</span>;
<span class="hljs-keyword">import</span> { foo } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;bar&quot;</span>;
<span class="hljs-keyword">import</span> { foo <span class="hljs-keyword">as</span> bar } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;baz&quot;</span>;

<span class="hljs-keyword">export</span> { foo };
<span class="hljs-keyword">export</span> { foo <span class="hljs-keyword">as</span> bar };
<span class="hljs-keyword">export</span> { foo <span class="hljs-keyword">as</span> bar } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;foo&quot;</span>;

<span class="hljs-keyword">let</span> { foo } = bar;
<span class="hljs-keyword">let</span> { foo: bar } = baz;
<span class="hljs-keyword">let</span> { [foo]: foo } = bar;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">{ bar }</span>) </span>{}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">{ bar: baz }</span>) </span>{}

({ foo }) =&gt; {}
({ foo: bar }) =&gt; {}
</code></pre>
</li>
</ul>
<h1 id="&#x8FED;&#x4EE3;&#x5668;&#x548C;&#x751F;&#x6210;&#x5668;"><a name="&#x8FED;&#x4EE3;&#x5668;&#x548C;&#x751F;&#x6210;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x8FED;&#x4EE3;&#x5668;&#x548C;&#x751F;&#x6210;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>11. &#x8FED;&#x4EE3;&#x5668;&#x548C;&#x751F;&#x6210;&#x5668;</h1>
<ul>
<li><p><a href="#11.1">11.1</a> <a name="11.1"></a> &#x4E0D;&#x8981;&#x4F7F;&#x7528; iterators&#x3002;&#x4F7F;&#x7528;&#x9AD8;&#x9636;&#x51FD;&#x6570;&#x4F8B;&#x5982; <code>map()</code> &#x548C; <code>reduce()</code> &#x66FF;&#x4EE3; <code>for-of</code>&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x52A0;&#x5F3A;&#x4E86;&#x6211;&#x4EEC;&#x4E0D;&#x53D8;&#x7684;&#x89C4;&#x5219;&#x3002;&#x5904;&#x7406;&#x7EAF;&#x51FD;&#x6570;&#x7684;&#x56DE;&#x8C03;&#x503C;&#x66F4;&#x6613;&#x8BFB;&#xFF0C;&#x8FD9;&#x6BD4;&#x5B83;&#x5E26;&#x6765;&#x7684;&#x526F;&#x4F5C;&#x7528;&#x66F4;&#x91CD;&#x8981;&#x3002;
&#x4F7F;&#x7528;<code>map()</code>/<code>every()</code>/<code>filter()</code>/<code>find()</code>/<code>findIndex()</code>/<code>reduce()</code>/<code>some()</code>/<code>...</code>&#x904D;&#x5386;&#x6570;&#x7EC4;&#xFF0C; &#x548C;&#x4F7F;&#x7528;<code>Object.keys()</code>/<code>Object.values()</code>/<code>Object.entries()</code>&#x8FED;&#x4EE3;&#x4F60;&#x7684;&#x5BF9;&#x8C61;&#x751F;&#x6210;&#x6570;&#x7EC4;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];

<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> num <span class="hljs-keyword">of</span> numbers) {
  sum += num;
}

sum === <span class="hljs-number">15</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];

<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
numbers.forEach((num) =&gt; sum += num);
sum === <span class="hljs-number">15</span>;

<span class="hljs-comment">// best (use the functional force)</span>
<span class="hljs-keyword">const</span> sum = numbers.reduce((total, num) =&gt; total + num, <span class="hljs-number">0</span>);
sum === <span class="hljs-number">15</span>;
</code></pre>
</li>
</ul>
<h1 id="&#x5C5E;&#x6027;"><a name="&#x5C5E;&#x6027;" class="anchor-navigation-ex-anchor" href="#&#x5C5E;&#x6027;"><i class="fa fa-link" aria-hidden="true"></i></a>12. &#x5C5E;&#x6027;</h1>
<ul>
<li><p><a href="#12.1">12.1</a> <a name="12.1"></a> &#x4F7F;&#x7528; <code>.</code> &#x6765;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js/#L39" target="_blank"><code>dot-notation</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> luke = {
  jedi: <span class="hljs-literal">true</span>,
  age: <span class="hljs-number">28</span>,
};

<span class="hljs-keyword">const</span> isJedi = luke[<span class="hljs-string">&apos;jedi&apos;</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> luke = {
  jedi: <span class="hljs-literal">true</span>,
  age: <span class="hljs-number">28</span>,
};

<span class="hljs-keyword">const</span> isJedi = luke.jedi;
</code></pre>
</li>
<li><p><a href="#12.2">12.2</a> <a name="12.2"></a> &#x5F53;&#x901A;&#x8FC7;&#x53D8;&#x91CF;&#x8BBF;&#x95EE;&#x5C5E;&#x6027;&#x65F6;&#x4F7F;&#x7528;&#x4E2D;&#x62EC;&#x53F7; <code>[]</code>&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> luke = {
  jedi: <span class="hljs-literal">true</span>,
  age: <span class="hljs-number">28</span>,
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getProp</span>(<span class="hljs-params">prop</span>) </span>{
  <span class="hljs-keyword">return</span> luke[prop];
}

<span class="hljs-keyword">const</span> isJedi = getProp(<span class="hljs-string">&apos;jedi&apos;</span>);
</code></pre>
</li>
<li><p><a href="#12.3">12.3</a> <a name="12.3"></a> &#x89C4;&#x5B9A;&#x58F0;&#x660E;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x65F6;&#x53EA;&#x80FD;&#x4E00;&#x884C;&#x58F0;&#x660E;&#x6240;&#x6709;&#x7684;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x6BCF;&#x884C;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L477" target="_blank"><code>object-property-newline</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj1 = { foo: <span class="hljs-string">&apos;foo&apos;</span>, bar: <span class="hljs-string">&apos;bar&apos;</span>,
  baz: <span class="hljs-string">&apos;baz&apos;</span>,
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj1 = { foo: <span class="hljs-string">&apos;foo&apos;</span>, bar: <span class="hljs-string">&apos;bar&apos;</span>, baz: <span class="hljs-string">&apos;baz&apos;</span> };
<span class="hljs-keyword">const</span> obj2 = {
  foo: <span class="hljs-string">&apos;foo&apos;</span>,
  bar: <span class="hljs-string">&apos;bar&apos;</span>,
  baz: <span class="hljs-string">&apos;baz&apos;</span>,
};
</code></pre>
</li>
<li><p><a href="#12.4">12.4</a> <a name="12.4"></a> &#x7981;&#x6B62;&#x4F7F;&#x7528;<code>__proto__</code>&#x5C5E;&#x6027;&#xFF0C;<code>__proto__</code>&#x5C5E;&#x6027;&#x5DF2;&#x4ECE;ECMAScript 3.1&#x5F00;&#x59CB;&#x5F03;&#x7528;&#xFF0C;&#x4E0D;&#x5E94;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x4F7F;&#x7528;&#xFF0C;&#x6539;&#x7528;<code>getPrototypeOf</code>&#x65B9;&#x6CD5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L243" target="_blank"><code>no-proto</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = obj.__proto__;
<span class="hljs-keyword">const</span> a = obj[<span class="hljs-string">&apos;__proto__&apos;</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-built_in">Object</span>.getPrototypeOf(obj);
</code></pre>
</li>
</ul>
<h1 id="&#x53D8;&#x91CF;"><a name="&#x53D8;&#x91CF;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>13. &#x53D8;&#x91CF;</h1>
<ul>
<li><p><a href="#13.1">13.1</a> <a name="13.1"></a> &#x53D8;&#x91CF;&#x7684;&#x540D;&#x79F0;&#x91C7;&#x7528;&#x5C0F;&#x9A7C;&#x5CF0;&#x6CD5;&#x5219;&#xFF0C;&#x9996;&#x5B57;&#x6BCD;&#x5C0F;&#x5199;&#xFF0C;&#x540E;&#x7EED;&#x5355;&#x8BCD;&#x7684;&#x9996;&#x5B57;&#x6BCD;&#x5927;&#x5199;&#x3002;&#x53D8;&#x91CF;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x4E0D;&#x9700;&#x8981;&#x9075;&#x5FAA;&#x8BE5;&#x89C4;&#x5219;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L19" target="_blank"><code>camelcase</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> Is_Editable = <span class="hljs-literal">false</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> isEditable = <span class="hljs-literal">false</span>;
<span class="hljs-keyword">const</span> obj = {
  my_pref: <span class="hljs-number">1</span>,
  <span class="hljs-string">&apos;my-pref&apos;</span>: <span class="hljs-number">2</span>,
};
</code></pre>
</li>
<li><p><a href="#13.2">13.2</a> <a name="13.2"></a> &#x4E00;&#x76F4;&#x4F7F;&#x7528; <code>const</code> &#x6765;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x8FD9;&#x6837;&#x505A;&#x5C31;&#x4F1A;&#x4EA7;&#x751F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x907F;&#x514D;&#x5168;&#x5C40;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x6C61;&#x67D3;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js/#L34" target="_blank"><code>no-undef</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">superPower = <span class="hljs-keyword">new</span> SuperPower();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> superPower = <span class="hljs-keyword">new</span> SuperPower();
</code></pre>
</li>
<li><p><a href="#13.3">13.3</a> <a name="13.3"></a> &#x4F7F;&#x7528; <code>const</code> &#x58F0;&#x660E;&#x6BCF;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L127" target="_blank"><code>prefer-const</code></a>  <a href=""><code>one-var</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x6837;&#x66F4;&#x5BB9;&#x6613;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#xFF0C;&#x800C;&#x4E14;&#x4F60;&#x4E0D;&#x5FC5;&#x62C5;&#x5FC3;&#x662F;&#x4F7F;&#x7528; ; &#x8FD8;&#x662F;&#x4F7F;&#x7528; , &#x6216;&#x5F15;&#x5165;&#x6807;&#x70B9;&#x7B26;&#x53F7;&#x7684;&#x5DEE;&#x522B;&#x3002; &#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; debugger &#x9010;&#x6B65;&#x67E5;&#x770B;&#x6BCF;&#x4E2A;&#x58F0;&#x660E;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x7ACB;&#x5373;&#x8DF3;&#x8FC7;&#x6240;&#x6709;&#x58F0;&#x660E;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = getItems(),
    goSportsTeam = <span class="hljs-literal">true</span>,
    dragonball = <span class="hljs-string">&apos;z&apos;</span>;

<span class="hljs-comment">// (compare to above, and try to spot the mistake)</span>
<span class="hljs-keyword">const</span> items = getItems(),
    goSportsTeam = <span class="hljs-literal">true</span>;
    dragonball = <span class="hljs-string">&apos;z&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = getItems();
<span class="hljs-keyword">const</span> goSportsTeam = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">const</span> dragonball = <span class="hljs-string">&apos;z&apos;</span>;
</code></pre>
</li>
<li><p><a href="#13.4">13.4</a> <a name="13.4"></a> &#x5C06;&#x6240;&#x6709;&#x7684; <code>const</code> &#x548C; <code>let</code> &#x5206;&#x7EC4;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x5728;&#x540E;&#x8FB9;&#x5982;&#x679C;&#x9700;&#x8981;&#x6839;&#x636E;&#x524D;&#x8FB9;&#x7684;&#x8D4B;&#x503C;&#x53D8;&#x91CF;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x65F6;&#x5F88;&#x6709;&#x7528;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> i, len, dragonball,
    items = getItems(),
    goSportsTeam = <span class="hljs-literal">true</span>;

<span class="hljs-keyword">let</span> i;
<span class="hljs-keyword">const</span> items = getItems();
<span class="hljs-keyword">let</span> dragonball;
<span class="hljs-keyword">const</span> goSportsTeam = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">let</span> len;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> goSportsTeam = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">const</span> items = getItems();
<span class="hljs-keyword">let</span> dragonball;
<span class="hljs-keyword">let</span> i;
<span class="hljs-keyword">let</span> length;
</code></pre>
</li>
<li><p><a href="#13.5">13.5</a> <a name="13.5"></a> &#x5728;&#x4F60;&#x9700;&#x8981;&#x7684;&#x5730;&#x65B9;&#x7ED9;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#xFF0C;&#x4F46;&#x8BF7;&#x628A;&#x5B83;&#x4EEC;&#x653E;&#x5728;&#x4E00;&#x4E2A;&#x5408;&#x7406;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;<code>let</code> &#x548C; <code>const</code> &#x662F;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x800C;&#x4E0D;&#x662F;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">hasName</span>) </span>{
  <span class="hljs-keyword">const</span> name = getName();

  <span class="hljs-keyword">if</span> (!hasName) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }

  <span class="hljs-keyword">this</span>.setFirstName(name);

  <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
<p><em>[&#x8BF4;&#x660E;] unnecessary function call&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  test();
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;doing stuff..&apos;</span>);

  <span class="hljs-comment">//..other stuff..</span>

  <span class="hljs-keyword">const</span> name = getName();

  <span class="hljs-keyword">if</span> (name === <span class="hljs-string">&apos;test&apos;</span>) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }

  <span class="hljs-keyword">return</span> name;
}

<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">hasName</span>) </span>{
  <span class="hljs-keyword">if</span> (!hasName) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }

  <span class="hljs-keyword">const</span> name = getName();
  <span class="hljs-keyword">this</span>.setFirstName(name);

  <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
</li>
<li><p><a href="#13.6">13.6</a> <a name="13.6"></a> &#x7981;&#x6B62;&#x91CD;&#x65B0;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js/#L247" target="_blank"><code>no-redeclare</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">3</span>;
<span class="hljs-keyword">let</span> a = <span class="hljs-number">10</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">3</span>;
a = <span class="hljs-number">10</span>;
</code></pre>
</li>
<li><p><a href="#13.7">13.7</a> <a name="13.7"></a> &#x907F;&#x514D;&#x4F7F;&#x7528;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x9012;&#x589E;&#x548C;&#x9012;&#x51CF; (++, --)&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js/#L17" target="_blank"><code>no-plusplus</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x5728;<code>eslint</code>&#x6587;&#x6863;&#x4E2D;&#xFF0C;&#x4E00;&#x5143;&#x9012;&#x589E;&#x548C;&#x9012;&#x51CF;&#x8BED;&#x53E5;&#x4EE5;&#x81EA;&#x52A8;&#x5206;&#x53F7;&#x63D2;&#x5165;&#x4E3A;&#x4E3B;&#x9898;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E2D;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x9ED8;&#x8BA4;&#x503C;&#x7684;&#x9012;&#x589E;&#x6216;&#x9012;&#x51CF;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>num += 1</code>&#x8FD9;&#x6837;&#x7684;&#x8BED;&#x53E5;&#x6765;&#x6539;&#x53D8;&#x60A8;&#x7684;&#x503C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4F7F;&#x7528;<code>num++</code>&#x6216;<code>num ++</code>&#x3002;&#x4E0D;&#x5141;&#x8BB8;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x589E;&#x91CF;&#x548C;&#x51CF;&#x91CF;&#x8BED;&#x53E5;&#x4E5F;&#x4F1A;&#x4F7F;&#x60A8;&#x65E0;&#x6CD5;&#x9884;&#x5148;&#x9012;&#x589E;/&#x9884;&#x9012;&#x51CF;&#x503C;&#xFF0C;&#x8FD9;&#x4E5F;&#x4F1A;&#x5BFC;&#x81F4;&#x7A0B;&#x5E8F;&#x4E2D;&#x7684;&#x610F;&#x5916;&#x884C;&#x4E3A;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> array = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">let</span> num = <span class="hljs-number">1</span>;
num++;
--num;

<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
<span class="hljs-keyword">let</span> truthyCount = <span class="hljs-number">0</span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; array.length; i++) {
  <span class="hljs-keyword">let</span> value = array[i];
  sum += value;
  <span class="hljs-keyword">if</span> (value) {
    truthyCount++;
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> array = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">let</span> num = <span class="hljs-number">1</span>;
num += <span class="hljs-number">1</span>;
num -= <span class="hljs-number">1</span>;

<span class="hljs-keyword">const</span> sum = array.reduce((a, b) =&gt; a + b, <span class="hljs-number">0</span>);
<span class="hljs-keyword">const</span> truthyCount = array.filter(<span class="hljs-built_in">Boolean</span>).length;
</code></pre>
</li>
<li><p><a href="#13.8">13.8</a> <a name="13.8"></a> &#x7981;&#x6B62;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x4E0E;&#x5916;&#x5C42;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;&#x540C;&#x540D;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js/#L26" target="_blank"><code>no-shadow</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">3</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> a = <span class="hljs-number">10</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">3</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> c = <span class="hljs-number">10</span>;
}
</code></pre>
</li>
<li><p><a href="#13.9">13.9</a> <a name="13.9"></a> &#x7981;&#x6B62;&#x4F7F;&#x7528;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#x3002;&#x7981;&#x6B62;&#x5728;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x4E4B;&#x524D;&#x4F7F;&#x7528;&#x5B83;&#x4EEC;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js#L34" target="_blank"><code>no-undef</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js.js#L51" target="_blank"><code>no-use-before-define</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">5</span>;
b = <span class="hljs-number">10</span>;
f();
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">5</span>;
a = <span class="hljs-number">10</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
f();
</code></pre>
</li>
<li><p><a href="#13.10">13.10</a> <a name="13.10"></a> &#x4E0D;&#x5141;&#x8BB8;&#x521D;&#x59CB;&#x5316;&#x53D8;&#x91CF;&#x503C;&#x4E3A; <code>undefined</code>&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js#L38" target="_blank"><code>no-undef-init</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> bar = <span class="hljs-literal">undefined</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> bar;
<span class="hljs-keyword">const</span> baz = <span class="hljs-literal">undefined</span>;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] const&#x58F0;&#x660E;&#x7684;&#x5E38;&#x91CF;&#x5FC5;&#x987B;&#x8981;&#x9996;&#x5148;&#x8D4B;&#x503C;&#x3002;</em></p>
</li>
<li><p><a href="#13.11">13.11</a> <a name="13.11"></a> &#x4E0D;&#x5141;&#x8BB8;&#x5B9A;&#x4E49;&#x4E86;&#x7684;&#x53D8;&#x91CF;&#x4F46;&#x662F;&#x5728;&#x540E;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#x6CA1;&#x6709;&#x88AB;&#x4F7F;&#x7528;&#x5230;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/variables.js#L47" target="_blank"><code>no-unused-vars</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">d</span>) </span>{
  <span class="hljs-keyword">const</span> y = <span class="hljs-number">10</span>;
  <span class="hljs-keyword">const</span> z = <span class="hljs-number">0</span>;
  <span class="hljs-built_in">console</span>.log(z);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">d</span>) </span>{
  <span class="hljs-built_in">console</span>.log(d);
}
</code></pre>
</li>
<li><p><a href="#13.12">13.12</a> <a name="13.12"></a> &#x7981;&#x6B62;&#x4F7F;&#x7528;&#x94FE;&#x5F0F;&#x8D4B;&#x503C;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L367" target="_blank"><code>no-multi-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = b = c = <span class="hljs-number">5</span>;
<span class="hljs-keyword">const</span> foo = bar = <span class="hljs-string">&apos;baz&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">5</span>;
<span class="hljs-keyword">const</span> b = <span class="hljs-number">5</span>;
<span class="hljs-keyword">const</span> c = <span class="hljs-number">5</span>;
<span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;baz&apos;</span>;
<span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;baz&apos;</span>;
</code></pre>
</li>
<li><p><a href="#13.13">13.13</a> <a name="13.13"></a> &#x628A;&#x53D8;&#x91CF;&#x7684;&#x4F7F;&#x7528;&#x9650;&#x5236;&#x5728;&#x5176;&#x5B9A;&#x4E49;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x8303;&#x56F4;&#x5185;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L12" target="_blank"><code>block-scoped-var</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doIf</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
      <span class="hljs-keyword">var</span> build = <span class="hljs-literal">true</span>;
  }

  <span class="hljs-built_in">console</span>.log(build);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doIfElse</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
        <span class="hljs-keyword">var</span> build = <span class="hljs-literal">true</span>;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">var</span> build = <span class="hljs-literal">false</span>;
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doTryCatch</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">var</span> build = <span class="hljs-number">1</span>;
    } <span class="hljs-keyword">catch</span> (e) {
        <span class="hljs-keyword">var</span> f = build;
    }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doIf</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">let</span> build;

<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
    build = <span class="hljs-literal">true</span>;
}

<span class="hljs-built_in">console</span>.log(build);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doIfElse</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">let</span> build;

    <span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
        build = <span class="hljs-literal">true</span>;
    } <span class="hljs-keyword">else</span> {
        build = <span class="hljs-literal">false</span>;
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doTryCatch</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">let</span> build;
    <span class="hljs-keyword">let</span> f;

    <span class="hljs-keyword">try</span> {
        build = <span class="hljs-number">1</span>;
    } <span class="hljs-keyword">catch</span> (e) {
        f = build;
    }
}
</code></pre>
</li>
<li><p><a href="#13.14">13.14</a> <a name="13.14"></a> &#x7981;&#x6B62;&#x4FEE;&#x6539;&#x7C7B;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L44" target="_blank"><code>no-class-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> A = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span> </span>{
  b() {
    A = <span class="hljs-number">0</span>;
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span> </span>{
  b(A) {
    A = <span class="hljs-number">0</span>; <span class="hljs-comment">// A is a parameter.</span>
  }
}
</code></pre>
</li>
</ul>
<h1 id="&#x63D0;&#x5347;"><a name="&#x63D0;&#x5347;" class="anchor-navigation-ex-anchor" href="#&#x63D0;&#x5347;"><i class="fa fa-link" aria-hidden="true"></i></a>14. &#x63D0;&#x5347;</h1>
<ul>
<li><p><a href="#14.1">14.1</a> <a name="14.1"></a> <code>var</code> &#x58F0;&#x660E;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x81F3;&#x8BE5;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x9876;&#x90E8;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x8D4B;&#x503C;&#x4E0D;&#x4F1A;&#x63D0;&#x5347;&#x3002;<code>let</code> &#x548C; <code>const</code> &#x88AB;&#x8D4B;&#x4E88;&#x4E86;&#x4E00;&#x79CD;&#x79F0;&#x4E3A;&#x300C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let" target="_blank">&#x6682;&#x65F6;&#x6027;&#x6B7B;&#x533A;&#xFF08;Temporal Dead Zones, TDZ&#xFF09;</a>&#x300D;&#x7684;&#x6982;&#x5FF5;&#x3002;&#x8FD9;&#x5BF9;&#x4E8E;&#x4E86;&#x89E3;&#x4E3A;&#x4EC0;&#x4E48; <a href="http://es-discourse.com/t/why-typeof-is-no-longer-safe/15" target="_blank">type of &#x4E0D;&#x518D;&#x5B89;&#x5168;</a>&#x76F8;&#x5F53;&#x91CD;&#x8981;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x6211;&#x4EEC;&#x77E5;&#x9053;&#x8FD9;&#x6837;&#x8FD0;&#x884C;&#x4E0D;&#x4E86;</span>
<span class="hljs-comment">// &#xFF08;&#x5047;&#x8BBE; notDefined &#x4E0D;&#x662F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF09;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(notDefined); <span class="hljs-comment">// =&gt; throws a ReferenceError</span>
}

<span class="hljs-comment">// &#x7531;&#x4E8E;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x7684;&#x539F;&#x56E0;&#xFF0C;</span>
<span class="hljs-comment">// &#x5728;&#x5F15;&#x7528;&#x53D8;&#x91CF;&#x540E;&#x518D;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x662F;&#x53EF;&#x4EE5;&#x8FD0;&#x884C;&#x7684;&#x3002;</span>
<span class="hljs-comment">// &#x6CE8;&#xFF1A;&#x53D8;&#x91CF;&#x7684;&#x8D4B;&#x503C; `true` &#x4E0D;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x3002;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(declaredButNotAssigned); <span class="hljs-comment">// =&gt; undefined</span>
  <span class="hljs-keyword">var</span> declaredButNotAssigned = <span class="hljs-literal">true</span>;
}

<span class="hljs-comment">// &#x4F7F;&#x7528; const &#x548C; let</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(declaredButNotAssigned); <span class="hljs-comment">// =&gt; throws a ReferenceError</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> declaredButNotAssigned); <span class="hljs-comment">// =&gt; throws a ReferenceError</span>
  <span class="hljs-keyword">const</span> declaredButNotAssigned = <span class="hljs-literal">true</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x628A;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x63D0;&#x5347;&#x5230;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x9876;&#x5C42;&#xFF0C;</span>
<span class="hljs-comment">// &#x8FD9;&#x610F;&#x5473;&#x7740;&#x6211;&#x4EEC;&#x7684;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x6539;&#x5199;&#x6210;&#x8FD9;&#x6837;&#xFF1A;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">let</span> declaredButNotAssigned;
  <span class="hljs-built_in">console</span>.log(declaredButNotAssigned); <span class="hljs-comment">// =&gt; undefined</span>
  declaredButNotAssigned = <span class="hljs-literal">true</span>;
}
</code></pre>
</li>
<li><p><a href="#14.2">14.2</a> <a name="14.2"></a> &#x533F;&#x540D;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#xFF0C;&#x4F46;&#x51FD;&#x6570;&#x5185;&#x5BB9;&#x5E76;&#x4E0D;&#x4F1A;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(anonymous); <span class="hljs-comment">// =&gt; undefined</span>

  anonymous(); <span class="hljs-comment">// =&gt; TypeError anonymous is not a function</span>

  <span class="hljs-keyword">const</span> anonymous = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;anonymous function expression&apos;</span>);
  };
}
</code></pre>
</li>
<li><p><a href="#14.3">14.3</a> <a name="14.3"></a> &#x547D;&#x540D;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#xFF0C;&#x4F46;&#x51FD;&#x6570;&#x540D;&#x548C;&#x51FD;&#x6570;&#x5185;&#x5BB9;&#x5E76;&#x4E0D;&#x4F1A;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(named); <span class="hljs-comment">// =&gt; undefined</span>

  named(); <span class="hljs-comment">// =&gt; TypeError named is not a function</span>

  superPower(); <span class="hljs-comment">// =&gt; ReferenceError superPower is not defined</span>

  <span class="hljs-keyword">const</span> named = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">superPower</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Flying&apos;</span>);
  };
}

<span class="hljs-comment">// the same is true when the function name</span>
<span class="hljs-comment">// is the same as the variable name.</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(named); <span class="hljs-comment">// =&gt; undefined</span>

  named(); <span class="hljs-comment">// =&gt; TypeError named is not a function</span>

  <span class="hljs-keyword">const</span> named = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">named</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;named&apos;</span>);
  }
}
</code></pre>
</li>
<li><p><a href="#14.4">14.4</a> <a name="14.4"></a> &#x51FD;&#x6570;&#x58F0;&#x660E;&#x7684;&#x540D;&#x79F0;&#x548C;&#x51FD;&#x6570;&#x4F53;&#x90FD;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  superPower(); <span class="hljs-comment">// =&gt; Flying</span>

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">superPower</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Flying&apos;</span>);
  }
}
</code></pre>
</li>
</ul>
<h1 id="&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x7B49;&#x53F7;"><a name="&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x7B49;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x7B49;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>15. &#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x7B49;&#x53F7;</h1>
<ul>
<li><a href="#15.1">15.1</a> <a name="15.1"></a> &#x4F18;&#x5148;&#x4F7F;&#x7528; <code>===</code> &#x548C; <code>!==</code> &#x800C;&#x4E0D;&#x662F; <code>==</code> &#x548C; <code>!=</code>.eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js/#L48" target="_blank"><code>eqeqeq</code></a></li>
<li><p><a href="#15.2">15.2</a> <a name="15.2"></a> &#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x4F8B;&#x5982; <code>if</code> &#x8BED;&#x53E5;&#x901A;&#x8FC7;&#x62BD;&#x8C61;&#x65B9;&#x6CD5; <code>ToBoolean</code> &#x5F3A;&#x5236;&#x8BA1;&#x7B97;&#x5B83;&#x4EEC;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x5E76;&#x4E14;&#x603B;&#x662F;&#x9075;&#x5B88;&#x4E0B;&#x9762;&#x7684;&#x89C4;&#x5219;&#xFF1A;</p>
<ul>
<li><strong>&#x5BF9;&#x8C61;</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>true</strong></li>
<li><strong>Undefined</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong></li>
<li><strong>Null</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong></li>
<li><strong>&#x5E03;&#x5C14;&#x503C;</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>&#x5E03;&#x5C14;&#x7684;&#x503C;</strong></li>
<li><strong>&#x6570;&#x5B57;</strong> &#x5982;&#x679C;&#x662F; <strong>+0&#x3001;-0&#x3001;&#x6216; NaN</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong>, &#x5426;&#x5219;&#x4E3A; <strong>true</strong></li>
<li><strong>&#x5B57;&#x7B26;&#x4E32;</strong> &#x5982;&#x679C;&#x662F;&#x7A7A;&#x5B57;&#x7B26;&#x4E32; <code>&apos;&apos;</code> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong>&#xFF0C;&#x5426;&#x5219;&#x4E3A; <strong>true</strong></li>
</ul>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> ([<span class="hljs-number">0</span>]) {
  <span class="hljs-comment">// true</span>
  <span class="hljs-comment">// An array is an object, objects evaluate to true</span>
}
</code></pre>
</li>
<li><p><a href="#15.3">15.3</a> <a name="15.3"></a> &#x5BF9;&#x4E8E;&#x5E03;&#x5C14;&#x503C;&#x4F7F;&#x7528;&#x7B80;&#x5199;&#xFF0C;&#x4F46;&#x662F;&#x5BF9;&#x4E8E;&#x5B57;&#x7B26;&#x4E32;&#x548C;&#x6570;&#x5B57;&#x8FDB;&#x884C;&#x663E;&#x5F0F;&#x6BD4;&#x8F83;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (isValid === <span class="hljs-literal">true</span>) {
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-keyword">if</span> (name) {
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-keyword">if</span> (collection.length) {
  <span class="hljs-comment">// ...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (isValid) {
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-keyword">if</span> (name !== <span class="hljs-string">&apos;&apos;</span>) {
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-keyword">if</span> (collection.length &gt; <span class="hljs-number">0</span>) {
  <span class="hljs-comment">// ...</span>
}
</code></pre>
</li>
<li><p><a href="#15.4">15.4</a> <a name="15.4"></a> &#x5BF9;&#x4E8E;&#x7EDD;&#x5927;&#x591A;&#x6570;&#x7684;&#x4F7F;&#x7528;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7ED3;&#x679C;typeof&#x64CD;&#x4F5C;&#x662F;&#x4E0B;&#x5217;&#x5B57;&#x7B26;&#x4E32;&#x5E38;&#x91CF;&#x4E4B;&#x4E00;&#xFF1A;&quot;undefined&quot;&#xFF0C;&quot;object&quot;&#xFF0C;&quot;boolean&quot;&#xFF0C;&quot;number&quot;&#xFF0C;&quot;string&quot;&#xFF0C;&quot;function&quot;&#x548C;&quot;symbol&quot;&#x3002;&#x5C06;typeof&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x7ED3;&#x679C;&#x4E0E;&#x5176;&#x4ED6;&#x5B57;&#x7B26;&#x4E32;&#x6587;&#x5B57;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#x901A;&#x5E38;&#x662F;&#x4EE3;&#x7801;&#x7F16;&#x5199;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L177" target="_blank"><code>valid-typeof</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">typeof</span> foo === <span class="hljs-literal">undefined</span>;
<span class="hljs-keyword">typeof</span> bar == <span class="hljs-built_in">Object</span>;
<span class="hljs-keyword">typeof</span> baz === <span class="hljs-string">&apos;strnig&apos;</span>;
<span class="hljs-keyword">typeof</span> qux === <span class="hljs-string">&apos;some invalid type&apos;</span>;
<span class="hljs-keyword">typeof</span> baz === anotherVariable;
<span class="hljs-keyword">typeof</span> foo == <span class="hljs-number">5</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">typeof</span> foo === <span class="hljs-string">&apos;undefined&apos;</span>;
<span class="hljs-keyword">typeof</span> bar == <span class="hljs-string">&apos;object&apos;</span>;
<span class="hljs-keyword">typeof</span> baz === <span class="hljs-string">&apos;string&apos;</span>;
<span class="hljs-keyword">typeof</span> bar === <span class="hljs-keyword">typeof</span> qux;
</code></pre>
</li>
<li><p><a href="#15.5">15.5</a> <a name="15.5"></a> &#x7981;&#x6B62;&#x51FA;&#x73B0;&#x4E0E;&#x672C;&#x8EAB;&#x4F5C;&#x6BD4;&#x8F83;&#x7684;&#x8BED;&#x53E5;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L313" target="_blank"><code>no-self-compare</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> x = <span class="hljs-number">10</span>;
<span class="hljs-keyword">if</span> (x === x) {
    x = <span class="hljs-number">20</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> x = <span class="hljs-number">10</span>;
<span class="hljs-keyword">const</span> y = <span class="hljs-number">10</span>;
<span class="hljs-keyword">if</span> (x === y) {
    x = <span class="hljs-number">20</span>;
}
</code></pre>
</li>
<li><p><a href="#15.6">15.6</a> <a name="15.6"></a> &#x7981;&#x6B62;&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x51FA;&#x73B0;&#x8D4B;&#x503C;&#x64CD;&#x4F5C;&#x7B26;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L29" target="_blank"><code>no-cond-assign</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> x;
<span class="hljs-keyword">if</span> (x = <span class="hljs-number">0</span>) {
    <span class="hljs-keyword">const</span> b = <span class="hljs-number">1</span>;
}

<span class="hljs-comment">// Practical example that is similar to an error</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setHeight</span>(<span class="hljs-params">someNode</span>) </span>{
<span class="hljs-meta">    &quot;use strict&quot;</span>;
    <span class="hljs-keyword">do</span> {
        someNode.height = <span class="hljs-string">&quot;100px&quot;</span>;
    } <span class="hljs-keyword">while</span> (someNode = someNode.parentNode);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x;
<span class="hljs-keyword">if</span> (x === <span class="hljs-number">0</span>) {
    <span class="hljs-keyword">const</span> b = <span class="hljs-number">1</span>;
}
</code></pre>
</li>
<li><p><a href="#15.7">15.7</a> <a name="15.7"></a> &#x7981;&#x6B62;&#x5BF9;&#x5173;&#x7CFB;&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x5DE6;&#x64CD;&#x4F5C;&#x6570;&#x4F7F;&#x7528;&#x5426;&#x5B9A;&#x8FD0;&#x7B97;&#x7B26;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L151" target="_blank"><code>no-unsafe-negation</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (!key <span class="hljs-keyword">in</span> object) {
    <span class="hljs-comment">// operator precedence makes it equivalent to (!key) in object</span>
    <span class="hljs-comment">// and type conversion makes it equivalent to (key ? &quot;false&quot; : &quot;true&quot;) in object</span>
}
<span class="hljs-keyword">if</span> (!obj <span class="hljs-keyword">instanceof</span> Ctor) {
    <span class="hljs-comment">// operator precedence makes it equivalent to (!obj) instanceof Ctor</span>
    <span class="hljs-comment">// and it equivalent to always false since boolean values are not objects.</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (!(key <span class="hljs-keyword">in</span> object)) {
    <span class="hljs-comment">// key is not in object</span>
}
<span class="hljs-keyword">if</span> (!(obj <span class="hljs-keyword">instanceof</span> Ctor)) {
    <span class="hljs-comment">// obj is not an instance of Ctor</span>
}
<span class="hljs-keyword">if</span>((<span class="hljs-string">&apos;&apos;</span> + !key) <span class="hljs-keyword">in</span> object) {
    <span class="hljs-comment">// make operator precedence and type conversion explicit</span>
    <span class="hljs-comment">// in a rare situation when that is the intended meaning</span>
}
</code></pre>
</li>
<li><p><a href="#15.8">15.8</a> <a name="15.8"></a> &#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x6269;&#x5C55;&#x8FD0;&#x7B97;&#x7B26;&#x800C;&#x975E;<code>.apply()</code>&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L166" target="_blank"><code>prefer-spread</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">foo.apply(<span class="hljs-literal">undefined</span>, args);
foo.apply(<span class="hljs-literal">null</span>, args);
obj.foo.apply(obj, args);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo(...args);
obj.foo(...args);
</code></pre>
</li>
<li><p><a href="#15.9">15.9</a> <a name="15.9"></a> &#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x5E94;&#x8BE5;&#x5D4C;&#x5957;&#xFF0C;&#x901A;&#x5E38;&#x662F;&#x5355;&#x884C;&#x8868;&#x8FBE;&#x5F0F;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L166" target="_blank"><code>no-nested-ternary</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = maybe1 &gt; maybe2
  ? <span class="hljs-string">&quot;bar&quot;</span>
  : value1 &gt; value2 ? <span class="hljs-string">&quot;baz&quot;</span> : <span class="hljs-literal">null</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B; good</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> maybeNull = value1 &gt; value2 ? <span class="hljs-string">&apos;baz&apos;</span> : <span class="hljs-literal">null</span>;
<span class="hljs-keyword">const</span> foo = maybe1 &gt; maybe2
  ? <span class="hljs-string">&apos;bar&apos;</span>
  : maybeNull;
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x5206;&#x79BB;&#x4E3A;&#x4E24;&#x4E2A;&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B; best</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> maybeNull = value1 &gt; value2 ? <span class="hljs-string">&apos;baz&apos;</span> : <span class="hljs-literal">null</span>;
<span class="hljs-keyword">const</span> foo = maybe1 &gt; maybe2 ? <span class="hljs-string">&apos;bar&apos;</span> : maybeNull;
</code></pre>
</li>
</ul>
<h1 id="&#x4EE3;&#x7801;&#x5757;"><a name="&#x4EE3;&#x7801;&#x5757;" class="anchor-navigation-ex-anchor" href="#&#x4EE3;&#x7801;&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>16. &#x4EE3;&#x7801;&#x5757;</h1>
<ul>
<li><p><a href="#16.1">16.1</a> <a name="16.1"></a> &#x4F7F;&#x7528;&#x5927;&#x62EC;&#x53F7;&#x5305;&#x88F9;&#x6240;&#x6709;&#x7684;&#x591A;&#x884C;&#x4EE3;&#x7801;&#x5757;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js/#L31" target="_blank"><code>curly</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test)
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; }
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;

<span class="hljs-keyword">if</span> (test) {
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}
</code></pre>
</li>
<li><p><a href="#16.2">16.2</a> <a name="16.2"></a> &#x5982;&#x679C;&#x901A;&#x8FC7; <code>if</code> &#x548C; <code>else</code> &#x4F7F;&#x7528;&#x591A;&#x884C;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x628A; <code>else</code> &#x653E;&#x5728; <code>if</code> &#x4EE3;&#x7801;&#x5757;&#x5173;&#x95ED;&#x62EC;&#x53F7;&#x7684;&#x540C;&#x4E00;&#x884C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L24" target="_blank"><code>brace-style</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test) {
  thing1();
  thing2();
}
<span class="hljs-keyword">else</span> {
  thing3();
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (test) {
  thing1();
  thing2();
} <span class="hljs-keyword">else</span> {
  thing3();
}
</code></pre>
</li>
</ul>
<h1 id="&#x6CE8;&#x91CA;"><a name="&#x6CE8;&#x91CA;" class="anchor-navigation-ex-anchor" href="#&#x6CE8;&#x91CA;"><i class="fa fa-link" aria-hidden="true"></i></a>17. &#x6CE8;&#x91CA;</h1>
<ul>
<li><p><a href="#17.1">17.1</a> <a name="17.1"></a> &#x4F7F;&#x7528; <code>/** ... */</code> &#x4F5C;&#x4E3A;&#x591A;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5305;&#x542B;&#x63CF;&#x8FF0;&#x3001;&#x6307;&#x5B9A;&#x6240;&#x6709;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x548C;&#x503C;&#x3002;&#x5E76;&#x4E14;&#x591A;&#x884C;&#x6CE8;&#x91CA;&#x4E0E;&#x4E0A;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#x4E4B;&#x95F4;&#x8981;&#x7A7A;&#x4E00;&#x884C;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// make() returns a new element</span>
<span class="hljs-comment">// based on the passed in tag name</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">// @param {String} tag</span>
<span class="hljs-comment">// @return {Element} element</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">make</span>(<span class="hljs-params">tag</span>) </span>{

  <span class="hljs-comment">// ...stuff...</span>

  <span class="hljs-keyword">return</span> element;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * make() returns a new element
 * based on the passed in tag name
 *
 * @param {String} tag
 * @return {Element} element
 */</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">make</span>(<span class="hljs-params">tag</span>) </span>{

  <span class="hljs-comment">// ...stuff...</span>

  <span class="hljs-keyword">return</span> element;
}
</code></pre>
</li>
<li><p><a href="#17.2">17.2</a> <a name="17.2"></a> &#x4F7F;&#x7528; <code>//</code> &#x4F5C;&#x4E3A;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5728;&#x8BC4;&#x8BBA;&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#x53E6;&#x8D77;&#x4E00;&#x884C;&#x4F7F;&#x7528;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5728;&#x6CE8;&#x91CA;&#x524D;&#x63D2;&#x5165;&#x7A7A;&#x884C;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L211" target="_blank"><code>lines-around-comment</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> active = <span class="hljs-literal">true</span>;  <span class="hljs-comment">// is current tab</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getType</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;fetching type...&apos;</span>);
  <span class="hljs-comment">// set the default type to &apos;no type&apos;</span>
  <span class="hljs-keyword">const</span> type = <span class="hljs-keyword">this</span>._type || <span class="hljs-string">&apos;no type&apos;</span>;

  <span class="hljs-keyword">return</span> type;
}
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x6CE8;&#x91CA;&#x9519;&#x8BEF;&#x3002;</em></p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// is current tab</span>
<span class="hljs-keyword">const</span> active = <span class="hljs-literal">true</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getType</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;fetching type...&apos;</span>);

  <span class="hljs-comment">// set the default type to &apos;no type&apos;</span>
  <span class="hljs-keyword">const</span> type = <span class="hljs-keyword">this</span>._type || <span class="hljs-string">&apos;no type&apos;</span>;

  <span class="hljs-keyword">return</span> type;
}
</code></pre>
<p><em>[&#x8BF4;&#x660E;] &#x6CE8;&#x91CA;&#x6B63;&#x786E;&#x3002;</em></p>
</li>
</ul>
<ul>
<li><p><a href="#17.3">17.3</a> <a name="17.3"></a> &#x7ED9;&#x6CE8;&#x91CA;&#x589E;&#x52A0; <code>FIXME</code> &#x6216; <code>TODO</code> &#x7684;&#x524D;&#x7F00;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x5176;&#x4ED6;&#x5F00;&#x53D1;&#x8005;&#x5FEB;&#x901F;&#x4E86;&#x89E3;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x9700;&#x8981;&#x590D;&#x67E5;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6216;&#x662F;&#x7ED9;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x529F;&#x80FD;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x89E3;&#x51B3;&#x65B9;&#x5F0F;&#x3002;&#x8FD9;&#x5C06;&#x6709;&#x522B;&#x4E8E;&#x5E38;&#x89C1;&#x7684;&#x6CE8;&#x91CA;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x662F;&#x53EF;&#x64CD;&#x4F5C;&#x7684;&#x3002;&#x4F7F;&#x7528; <code>FIXME -- need to figure this out</code> &#x6216;&#x8005; <code>TODO -- need to implement</code>&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/best-practices.js#L292" target="_blank"><code>no-warning-comments</code></a></p>
</li>
<li><p><a href="#17.4">17.4</a> <a name="17.4"></a> &#x4F7F;&#x7528; <code>// FIXME</code>: &#x6807;&#x6CE8;&#x95EE;&#x9898;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calculator</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-comment">// <span class="hljs-doctag">FIXME:</span> shouldn&apos;t use a global here</span>
    total = <span class="hljs-number">0</span>;
  }
}
</code></pre>
</li>
<li><p><a href="#17.5">17.5</a> <a name="17.5"></a> &#x4F7F;&#x7528; <code>// TODO</code>: &#x6807;&#x6CE8;&#x95EE;&#x9898;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x5F0F;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calculator</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> total should be configurable by an options param</span>
    <span class="hljs-keyword">this</span>.total = <span class="hljs-number">0</span>;
  }
}
</code></pre>
</li>
</ul>
<h1 id="&#x7A7A;&#x767D;"><a name="&#x7A7A;&#x767D;" class="anchor-navigation-ex-anchor" href="#&#x7A7A;&#x767D;"><i class="fa fa-link" aria-hidden="true"></i></a>18. &#x7A7A;&#x767D;</h1>
<ul>
<li><p><a href="#18.1">18.1</a> <a name="18.1"></a> &#x4F7F;&#x7528; 2 &#x4E2A;&#x7A7A;&#x683C;&#x4F5C;&#x4E3A;&#x7F29;&#x8FDB;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
&#x2219;&#x2219;&#x2219;&#x2219;<span class="hljs-keyword">const</span> name;
}

<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
&#x2219;<span class="hljs-keyword">const</span> name;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
&#x2219;&#x2219;<span class="hljs-keyword">const</span> name;
}
</code></pre>
</li>
<li><p><a href="#18.2">18.2</a> <a name="18.2"></a> &#x5728;&#x9017;&#x53F7;&#x540E;&#x9762;&#x9700;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#xFF0C;&#x63D0;&#x9AD8;&#x5217;&#x8868;&#x9879;&#x7684;&#x53EF;&#x8BFB;&#x6027;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L59" target="_blank"><code>comma-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span> , <span class="hljs-number">2</span>];
<span class="hljs-keyword">const</span> obj = { foo: <span class="hljs-string">&apos;bar&apos;</span> ,baz: <span class="hljs-string">&apos;qur&apos;</span> };
foo(a ,b);
<span class="hljs-keyword">new</span> Foo(a ,b);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">a ,b</span>)</span>{}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>];
<span class="hljs-keyword">const</span> obj = { foo: <span class="hljs-string">&apos;bar&apos;</span>, baz: <span class="hljs-string">&apos;qur&apos;</span> };
foo(a, b);
<span class="hljs-keyword">new</span> Foo(a, b);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">a, b</span>)</span>{}
</code></pre>
</li>
<li><p><a href="#18.3">18.3</a> <a name="18.3"></a> &#x5728;&#x82B1;&#x62EC;&#x53F7;&#x524D;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L559" target="_blank"><code>space-before-blocks</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;test&apos;</span>);
}

dog.set(<span class="hljs-string">&apos;attr&apos;</span>,{
  age: <span class="hljs-string">&apos;1 year&apos;</span>,
  breed: <span class="hljs-string">&apos;Bernese Mountain Dog&apos;</span>,
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;test&apos;</span>);
}

dog.set(<span class="hljs-string">&apos;attr&apos;</span>, {
  age: <span class="hljs-string">&apos;1 year&apos;</span>,
  breed: <span class="hljs-string">&apos;Bernese Mountain Dog&apos;</span>,
});
</code></pre>
</li>
<li><p><a href="#18.4">18.4</a> <a name="18.4"></a>&#x5355;&#x884C;&#x5BF9;&#x8C61;&#x4EE3;&#x7801;&#x5757;&#x4E2D;&#xFF0C;&#x5757;&#x4E2D;&#x4EE3;&#x7801;&#x884C;&#x524D;&#x540E;&#x9700;&#x8981;&#x52A0;&#x7A7A;&#x683C;&#x3002;&#x6570;&#x7EC4;&#x4E0D;&#x9700;&#x8981;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/ngweb/eslint-config-ztesoft/blob/master/rules/styles.js#L463" target="_blank"><code>object-curly-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj = {foo: <span class="hljs-string">&apos;bar&apos;</span>};
<span class="hljs-keyword">const</span> test = {foo: <span class="hljs-string">&apos;bar&apos;</span> };
<span class="hljs-keyword">const</span> item = { baz: {foo: <span class="hljs-string">&apos;qux&apos;</span>}};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj = {};
<span class="hljs-keyword">const</span> test = { foo: <span class="hljs-string">&apos;bar&apos;</span> };
<span class="hljs-keyword">const</span> item = { foo: { bar: <span class="hljs-string">&apos;baz&apos;</span> }, qux: <span class="hljs-string">&apos;quxx&apos;</span> };
</code></pre>
</li>
<li><p><a href="#18.5">18.5</a> <a name="18.5"></a> &#x5728;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x3001;&#x533F;&#x540D;&#x51FD;&#x6570;&#x548C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7684;&#x5DE6;&#x62EC;&#x53F7;&#x4E4B;&#x524D;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002;&#x800C;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x7684;<code>function</code>&#x7684;&#x5DE6;&#x62EC;&#x53F7;&#x4E4B;&#x524D;&#x4E0D;&#x9700;&#x8981;&#x7A7A;&#x683C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L563" target="_blank"><code>space-before-function-paren</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">const</span> bar = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ...</span>
};
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  <span class="hljs-keyword">constructor</span> () {
    <span class="hljs-comment">// ...</span>
  }
}
<span class="hljs-keyword">const</span> foo = {
  bar () {
    <span class="hljs-comment">// ...</span>
  }
};
<span class="hljs-keyword">const</span> foo = <span class="hljs-keyword">async</span>(a) =&gt; <span class="hljs-keyword">await</span> a
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">const</span> bar = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ...</span>
};
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-comment">// ...</span>
  }
}
<span class="hljs-keyword">const</span> foo = {
  bar() {
    <span class="hljs-comment">// ...</span>
  }
};
<span class="hljs-keyword">const</span> foo = <span class="hljs-keyword">async</span> (a) =&gt; <span class="hljs-keyword">await</span> a
</code></pre>
</li>
<li><p><a href="#18.6">18.6</a> <a name="18.7"></a> &#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7BAD;&#x5934;&#x524D;&#x540E;&#x90FD;&#x5FC5;&#x987B;&#x8981;&#x6709;&#x7A7A;&#x683C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js/#L30" target="_blank"><code>arrow-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">()=&gt; {};
() =&gt;{};
(a)=&gt; {};
(a) =&gt;{};
a =&gt;a;
a=&gt; a;
()=&gt; {<span class="hljs-string">&apos;\n&apos;</span>};
() =&gt;{<span class="hljs-string">&apos;\n&apos;</span>};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">() =&gt; {};
(a) =&gt; {};
a =&gt; a;
() =&gt; {<span class="hljs-string">&apos;\n&apos;</span>};
</code></pre>
</li>
<li><p><a href="#18.7">18.7</a> <a name="18.8"></a> &#x5728;&#x63A7;&#x5236;&#x8BED;&#x53E5;&#xFF08;<code>if</code>&#x3001;<code>while</code> &#x7B49;&#xFF09;&#x7684;&#x5C0F;&#x62EC;&#x53F7;&#x524D;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x53CA;&#x58F0;&#x660E;&#x4E2D;&#xFF0C;&#x4E0D;&#x5728;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x5217;&#x8868;&#x524D;&#x52A0;&#x7A7A;&#x683C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L179" target="_blank"><code>keyword-spacing</code></a></p>
<ul>
<li>&#x4E00;&#x4E9B;&#x5173;&#x952E;&#x5B57;<code>yield</code>,<code>typeof</code>&#x7B49;&#x540E;&#x9762;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;</li>
</ul>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span>(isJedi) {
  fight ();
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fight</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log (<span class="hljs-string">&apos;Swooosh!&apos;</span>);
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (isJedi) {
  fight();
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fight</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Swooosh!&apos;</span>);
}
</code></pre>
</li>
<li><p><a href="#18.8">18.8</a> <a name="18.9"></a> &#x5728;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x8981;&#x6C42;&#x952E;&#x540D;&#x4E0E;&#x5192;&#x53F7;&#x4E4B;&#x95F4;&#x6CA1;&#x6709;&#x7A7A;&#x683C;&#xFF0C;&#x5192;&#x53F7;&#x4E0E;&#x503C;&#x4E4B;&#x95F4;&#x6709;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L175" target="_blank"><code>key-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj = { <span class="hljs-string">&apos;foo&apos;</span>:<span class="hljs-number">42</span> };
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj = { <span class="hljs-string">&apos;foo&apos;</span>: <span class="hljs-number">42</span> };
</code></pre>
</li>
<li><p><a href="#18.9">18.9</a> <a name="18.10"></a> &#x4F7F;&#x7528;&#x7A7A;&#x683C;&#x628A;&#x8FD0;&#x7B97;&#x7B26;&#x9694;&#x5F00;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L576" target="_blank"><code>space-infix-ops</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x=y+<span class="hljs-number">5</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x = y + <span class="hljs-number">5</span>;
</code></pre>
</li>
<li><p><a href="#18.10">18.10</a> <a name="18.11"></a> &#x4E00;&#x5143;&#x5B57;&#x6BCD;&#x64CD;&#x4F5C;&#x7B26;&#x524D;&#x540E;&#x9700;&#x8981;&#x52A0;&#x7A7A;&#x683C;&#xFF0C;&#x5982;&#xFF1A;new&#xFF0C;delete&#xFF0C;typeof&#xFF0C;void&#xFF0C;yield&#x3002;&#x4E00;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#x5982;-&#xFF0C;+&#xFF0C;--&#xFF0C;++&#xFF0C;!&#xFF0C;!!&#x524D;&#x540E;&#x4E0D;&#x7528;&#x52A0;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L580" target="_blank"><code>space-unary-ops</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">typeof</span>!foo;
<span class="hljs-keyword">void</span>{foo:<span class="hljs-number">0</span>};
<span class="hljs-keyword">new</span>[foo][<span class="hljs-number">0</span>];
<span class="hljs-keyword">delete</span>(foo.bar);
++ foo;
foo --;
- foo;
+ <span class="hljs-string">&apos;3&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">delete</span> foo.bar;
<span class="hljs-keyword">new</span> Foo;
<span class="hljs-keyword">void</span> <span class="hljs-number">0</span>;
++foo;
foo--;
-foo;
+<span class="hljs-string">&apos;3&apos;</span>;
</code></pre>
</li>
<li><p><a href="#18.11">18.11</a> <a name="18.12"></a> &#x4EE3;&#x7801;&#x6CE8;&#x91CA;&#x7B26;&#x53F7;&#x540E;&#x9762;&#x8981;&#x52A0;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L590" target="_blank"><code>spaced-comment</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//This is a comment with no whitespace at the beginning</span>

<span class="hljs-comment">/*This is a comment with no whitespace at the beginning */</span>
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// This is a comment with a whitespace at the beginning</span>

<span class="hljs-comment">/* This is a comment with a whitespace at the beginning */</span>
</code></pre>
</li>
<li><p><a href="#18.12">18.12</a> <a name="18.13"></a> &#x7981;&#x6B62;&#x5269;&#x4F59;&#x548C;&#x6269;&#x5C55;&#x8FD0;&#x7B97;&#x7B26;&#x53CA;&#x5176;&#x8868;&#x8FBE;&#x5F0F;&#x4E4B;&#x95F4;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/es6.js#L181" target="_blank"><code>rest-spread-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">fn(... args)
[... arr, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
<span class="hljs-keyword">let</span> [a, b, ... arr] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">... args</span>) </span>{ <span class="hljs-built_in">console</span>.log(args); }
<span class="hljs-keyword">let</span> { x, y, ... z } = { x: <span class="hljs-number">1</span>, y: <span class="hljs-number">2</span>, a: <span class="hljs-number">3</span>, b: <span class="hljs-number">4</span> };
<span class="hljs-keyword">let</span> n = { x, y, ... z };
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">fn(...args)
[...arr, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
<span class="hljs-keyword">let</span> [a, b, ...arr] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">...args</span>) </span>{ <span class="hljs-built_in">console</span>.log(args); }
<span class="hljs-keyword">let</span> { x, y, ...z } = { x: <span class="hljs-number">1</span>, y: <span class="hljs-number">2</span>, a: <span class="hljs-number">3</span>, b: <span class="hljs-number">4</span> };
<span class="hljs-keyword">let</span> n = { x, y, ...z };
</code></pre>
</li>
<li><p><a href="#18.13">18.13</a> <a name="18.14"></a> &#x907F;&#x514D;&#x5728;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L124" target="_blank"><code>no-regex-spaces</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> re = <span class="hljs-regexp">/foo   bar/</span>;
<span class="hljs-keyword">const</span> re = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;foo   bar&apos;</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> re = <span class="hljs-regexp">/foo {3}bar/</span>;
<span class="hljs-keyword">const</span> re = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;foo {3}bar&apos;</span>);
</code></pre>
</li>
<li><p><a href="#18.14">18.14</a> <a name="18.15"></a> &#x907F;&#x514D;&#x5728;&#x903B;&#x8F91;&#x8868;&#x8FBE;&#x5F0F;&#x3001;&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x3001;&#x58F0;&#x660E;&#x8BED;&#x53E5;&#x3001;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x3001;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x3001;&#x5E8F;&#x5217;&#x3001;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4E2D;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#xFF0C;&#x9664;&#x4E86;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#x7528;&#x4E8E;&#x7F29;&#x8FDB;&#x4EE5;&#x5916;&#xFF0C;&#x5176;&#x4ED6;&#x60C5;&#x51B5;&#x4E0B;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x7A7A;&#x683C;&#x901A;&#x5E38;&#x662F;&#x9519;&#x8BEF;&#x7684;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L192" target="_blank"><code>no-multi-spaces</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a =  <span class="hljs-number">1</span>;
<span class="hljs-keyword">if</span>(foo   === <span class="hljs-string">&apos;bar&apos;</span>) {}
a &lt;&lt;  b;
<span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>,  <span class="hljs-number">2</span>];
a ?  b: c;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">1</span>;
<span class="hljs-keyword">if</span>(foo === <span class="hljs-string">&apos;bar&apos;</span>) {}
a &lt;&lt; b
<span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>];
a ? b : c
</code></pre>
</li>
<li><p><a href="#18.15">18.15</a> <a name="18.16"></a> &#x7981;&#x6B62;&#x5728;&#x6570;&#x7EC4;&#x7684;&#x5DE6;&#x53F3;&#x65B9;&#x62EC;&#x53F7;&#x4E4B;&#x95F4;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L15" target="_blank"><code>array-bracket-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [ <span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-string">&apos;bar&apos;</span> ];
<span class="hljs-keyword">const</span> arr = [<span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-string">&apos;bar&apos;</span> ];
<span class="hljs-keyword">const</span> arr = [ [<span class="hljs-string">&apos;foo&apos;</span>], <span class="hljs-string">&apos;bar&apos;</span>];
<span class="hljs-keyword">const</span> arr = [[ <span class="hljs-string">&apos;foo&apos;</span> ], <span class="hljs-string">&apos;bar&apos;</span>];
<span class="hljs-keyword">const</span> arr = [ <span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>,
];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [];
<span class="hljs-keyword">const</span> arr = [<span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-string">&apos;bar&apos;</span>, <span class="hljs-string">&apos;baz&apos;</span>];
<span class="hljs-keyword">const</span> arr = [[<span class="hljs-string">&apos;foo&apos;</span>], <span class="hljs-string">&apos;bar&apos;</span>, <span class="hljs-string">&apos;baz&apos;</span>];
<span class="hljs-keyword">const</span> arr = [
  <span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>,
  <span class="hljs-string">&apos;baz&apos;</span>,
];
<span class="hljs-keyword">const</span> arr = [<span class="hljs-string">&apos;foo&apos;</span>,
  <span class="hljs-string">&apos;bar&apos;</span>,
];
</code></pre>
</li>
<li><p><a href="#18.16">18.16</a> <a name="18.17"></a> &#x5206;&#x53F7;&#x524D;&#x9762;&#x4E0D;&#x5E94;&#x8BE5;&#x6709;&#x7A7A;&#x683C;&#xFF0C;&#x5206;&#x53F7;&#x540E;&#x9762;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L542" target="_blank"><code>semi-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo ;
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&quot;error&quot;</span>) ;
<span class="hljs-keyword">while</span> (a) { <span class="hljs-keyword">break</span> ; }
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span> ; i &lt; <span class="hljs-number">10</span> ; i += <span class="hljs-number">1</span>) {}
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>;i &lt; <span class="hljs-number">10</span>;i += <span class="hljs-number">1</span>) {}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo;
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&quot;error&quot;</span>);
<span class="hljs-keyword">while</span> (a) { <span class="hljs-keyword">break</span>; }
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i += <span class="hljs-number">1</span>) {}
</code></pre>
</li>
<li><p><a href="#18.17">18.17</a> <a name="18.18"></a> &#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x7684;[]&#x5185;&#x4E0D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L81" target="_blank"><code>computed-property-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">obj[foo ];
obj[ <span class="hljs-string">&apos;foo&apos;</span>];
obj[foo[ bar ]];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">obj[foo];
obj[<span class="hljs-string">&apos;foo&apos;</span>];
obj[foo[bar]];
</code></pre>
</li>
<li><p><a href="#18.18">18.18</a> <a name="18.19"></a> &#x7981;&#x6B62;&#x884C;&#x672B;&#x5C3E;&#x6709;&#x7A7A;&#x683C;&#x3002;  eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L429" target="_blank"><code>no-trailing-spaces</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-number">0</span>;&#x2219;&#x2219;&#x2219;&#x2219;
<span class="hljs-keyword">const</span> baz = <span class="hljs-number">5</span>;&#x2219;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-number">0</span>;
<span class="hljs-keyword">const</span> baz = <span class="hljs-number">5</span>;
</code></pre>
</li>
</ul>
<!-- **注意:** 允许在空行中留空格，不会检验报错 -->
<ul>
<li><p><a href="#18.19">18.19</a> <a name="18.20"></a> &#x7981;&#x6B62;&#x5DE6;&#x53F3;&#x5706;&#x62EC;&#x53F7;()&#x4E0E;&#x5B83;&#x5185;&#x90E8;&#x7684;&#x5143;&#x7D20;&#x4E4B;&#x95F4;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L572" target="_blank"><code>space-in-parens</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">foo( <span class="hljs-string">&apos;bar&apos;</span>);
foo(<span class="hljs-string">&apos;bar&apos;</span> );
foo( <span class="hljs-string">&apos;bar&apos;</span> );
<span class="hljs-keyword">const</span> foo = ( <span class="hljs-number">1</span> + <span class="hljs-number">2</span> ) * <span class="hljs-number">3</span>;
( <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;bar&apos;</span>; }() );
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo();
foo(<span class="hljs-string">&apos;bar&apos;</span>);
<span class="hljs-keyword">const</span> foo = (<span class="hljs-number">1</span> + <span class="hljs-number">2</span>) * <span class="hljs-number">3</span>;
(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;bar&apos;</span>; }());
</code></pre>
</li>
<li><p><a href="#18.20">18.20</a> <a name="18.21"></a> &#x7981;&#x6B62;&#x5728;&#x51FD;&#x6570;&#x6807;&#x8BC6;&#x7B26;&#x548C;&#x5176;&#x8C03;&#x7528;&#x4E4B;&#x95F4;&#x6709;&#x7A7A;&#x683C;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L93" target="_blank"><code>func-call-spacing</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">fn ();
fn
();
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">fn();
</code></pre>
</li>
<li><p><a href="#18.21">18.21</a> <a name="18.22"></a> &#x5982;&#x679C;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4F4D;&#x4E8E;&#x540C;&#x4E00;&#x884C;&#xFF0C;&#x4E0D;&#x5141;&#x8BB8;&#x5728;&#x70B9;&#x5468;&#x56F4;&#x6216;&#x5F00;&#x59CB;&#x62EC;&#x53F7;&#x4E4B;&#x524D;&#x7684;&#x7A7A;&#x683C;&#x3002;&#x5F53;&#x5BF9;&#x8C61;&#x548C;&#x5C5E;&#x6027;&#x4F4D;&#x4E8E;&#x4E0D;&#x540C;&#x7684;&#x884C;&#x65F6;&#xFF0C;&#x5219;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x7A7A;&#x683C;&#xFF0C;&#x56E0;&#x4E3A;&#x901A;&#x5E38;&#x5C06;&#x65B0;&#x884C;&#x6DFB;&#x52A0;&#x5230;&#x8F83;&#x957F;&#x7684;&#x5C5E;&#x6027;&#x94FE;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L452" target="_blank"><code>no-whitespace-before-property</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">foo [bar];
foo. bar;
foo .bar;
foo. bar. baz;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo.bar;
foo[bar];
foo[ bar ];
foo.bar.baz;
foo
.bar()
.baz();
</code></pre>
</li>
<li><p><a href="#18.22">18.22</a> <a name="18.23"></a> &#x7981;&#x6B62;&#x4F7F;&#x7528;tab&#x952E;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L421" target="_blank"><code>no-tabs</code></a></p>
</li>
<li><p><a href="#18.23">18.23</a> <a name="18.24"></a> &#x5728;&#x4F7F;&#x7528;&#x957F;&#x65B9;&#x6CD5;&#x94FE;&#x65F6;&#x8FDB;&#x884C;&#x7F29;&#x8FDB;&#x3002;&#x4F7F;&#x7528;&#x524D;&#x9762;&#x7684;&#x70B9; <code>.</code> &#x5F3A;&#x8C03;&#x8FD9;&#x662F;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x800C;&#x4E0D;&#x662F;&#x65B0;&#x8BED;&#x53E5;&#x3002;.&#x53F7;&#x8C03;&#x7528;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x5E94;&#x4FDD;&#x6301;.&#x53F7;&#x4E0E;&#x5C5E;&#x6027;&#x5728;&#x540C;&#x4E00;&#x884C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L43" target="_blank"><code>dot-location</code></a></p>
<ul>
<li>&#x5355;&#x884C;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#xFF0C; &#x5E94;&#x4FDD;&#x6301;.&#x53F7;&#x4E0E;&#x5C5E;&#x6027;&#x5728;&#x540C;&#x4E00;&#x884C;</li>
<li>&#x6700;&#x591A;&#x53EA;&#x5141;&#x8BB8;4&#x4E2A;&#x5728;&#x540C;&#x4E00;&#x884C;&#xFF1B;&#x591A;&#x884C;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#xFF0C;&#x5E94;&#x4FDD;&#x6301;.&#x53F7;&#x4E0E;&#x5C5E;&#x6027;&#x5728;&#x540C;&#x4E00;&#x884C;</li>
</ul>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = object.
        property;

$(<span class="hljs-string">&apos;#items&apos;</span>).find(<span class="hljs-string">&apos;.selected&apos;</span>).highlight().end().find(<span class="hljs-string">&apos;.open&apos;</span>).updateCount();

$(<span class="hljs-string">&apos;#items&apos;</span>).
    find(<span class="hljs-string">&apos;.selected&apos;</span>).
    highlight().
    end().
    find(<span class="hljs-string">&apos;.open&apos;</span>).
    updateCount();

<span class="hljs-keyword">const</span> leds = stage.selectAll(<span class="hljs-string">&apos;.led&apos;</span>).data(data).enter().append(<span class="hljs-string">&apos;svg:svg&apos;</span>).class(<span class="hljs-string">&apos;led&apos;</span>, <span class="hljs-literal">true</span>)
    .attr(<span class="hljs-string">&apos;width&apos;</span>, (radius + margin) * <span class="hljs-number">2</span>).append(<span class="hljs-string">&apos;svg:g&apos;</span>)
    .attr(<span class="hljs-string">&apos;transform&apos;</span>, <span class="hljs-string">&apos;translate(&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;,&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;)&apos;</span>)
    .call(tron.led);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = object
        .property;
<span class="hljs-keyword">const</span> bar = object.property;

$(<span class="hljs-string">&apos;#items&apos;</span>)
    .find(<span class="hljs-string">&apos;.selected&apos;</span>)
    .highlight()
    .end()
    .find(<span class="hljs-string">&apos;.open&apos;</span>)
    .updateCount();

<span class="hljs-keyword">const</span> leds = stage.selectAll(<span class="hljs-string">&apos;.led&apos;</span>)
    .data(data)
    .enter().append(<span class="hljs-string">&apos;svg:svg&apos;</span>)
    .classed(<span class="hljs-string">&apos;led&apos;</span>, <span class="hljs-literal">true</span>)
    .attr(<span class="hljs-string">&apos;width&apos;</span>, (radius + margin) * <span class="hljs-number">2</span>)
    .append(<span class="hljs-string">&apos;svg:g&apos;</span>)
    .attr(<span class="hljs-string">&apos;transform&apos;</span>, <span class="hljs-string">&apos;translate(&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;,&apos;</span> + (radius + margin) + <span class="hljs-string">&apos;)&apos;</span>)
    .call(tron.led);
</code></pre>
</li>
<li><p><a href="#18.24">18.24</a> <a name="18.25"></a> &#x7C7B;&#x6210;&#x5458;&#x4E4B;&#x95F4;&#x9700;&#x8981;&#x6709;&#x7A7A;&#x884C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L206" target="_blank"><code>lines-between-class-members</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{
  foo() {
    <span class="hljs-comment">//...</span>
  }
  bar() {
    <span class="hljs-comment">//...</span>
  }
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{
  foo() {
    <span class="hljs-comment">//...</span>
  }

  bar() {
    <span class="hljs-comment">//...</span>
  }
}
</code></pre>
</li>
<li><p><a href="#18.25">18.25</a> <a name="18.26"></a> &#x5728;&#x5757;&#x672B;&#x548C;&#x65B0;&#x8BED;&#x53E5;&#x524D;&#x63D2;&#x5165;&#x7A7A;&#x884C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L559" target="_blank"><code>space-before-blocks</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (foo) {
  <span class="hljs-keyword">return</span> bar;
}
<span class="hljs-keyword">return</span> baz;

<span class="hljs-keyword">const</span> obj = {
  foo() {
  },
  bar() {
  },
};
<span class="hljs-keyword">return</span> obj;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (foo) {
  <span class="hljs-keyword">return</span> bar;
}

<span class="hljs-keyword">return</span> baz;

<span class="hljs-keyword">const</span> obj = {
  foo() {
  },

  bar() {
  },
};

<span class="hljs-keyword">return</span> obj;
</code></pre>
</li>
<li><p><a href="#18.26">18.26</a> <a name="18.27"></a> &#x4EE3;&#x7801;&#x4E2D;&#x6700;&#x591A;&#x8FDE;&#x7EED;&#x4F7F;&#x7528;&#x4E24;&#x884C;&#x7A7A;&#x884C;&#x3002;  eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L372" target="_blank"><code>no-multiple-empty-lines</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-number">5</span>;
&#x2219;&#x2219;&#x2219;&#x2219;
&#x2219;&#x2219;&#x2219;&#x2219;
&#x2219;&#x2219;&#x2219;&#x2219;
<span class="hljs-keyword">const</span> bar = <span class="hljs-number">3</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> foo = <span class="hljs-number">5</span>;
&#x2219;&#x2219;&#x2219;&#x2219;
<span class="hljs-keyword">const</span> bar = <span class="hljs-number">3</span>;
</code></pre>
</li>
<li><p><a href="#18.27">18.27</a> <a name="18.28"></a> &#x5728;&#x6587;&#x4EF6;&#x672B;&#x5C3E;&#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x7A7A;&#x884C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L89" target="_blank"><code>eol-last</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">global</span>) </span>{
  <span class="hljs-comment">// ...stuff...</span>
})(<span class="hljs-keyword">this</span>);

(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">global</span>) </span>{
  <span class="hljs-comment">// ...stuff...</span>
})(<span class="hljs-keyword">this</span>);&#x21B5;
&#x21B5;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">global</span>) </span>{
  <span class="hljs-comment">// ...stuff...</span>
})(<span class="hljs-keyword">this</span>);&#x21B5;
</code></pre>
</li>
<li><p><a href="#18.28">18.28</a> <a name="18.29"></a> &#x5728;&#x6700;&#x540E;&#x4E00;&#x7EC4;<code>import</code>&#x548C;<code>require</code>&#x540E;&#x8981;&#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x7A7A;&#x884C;&#x3002;eslint&#xFF1A;<a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/imports.js#L150" target="_blank"><code>import/newline-after-import</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">const</span> FOO = <span class="hljs-string">&apos;BAR&apos;</span>;
<span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;foo&apos;</span>;
<span class="hljs-keyword">const</span> FOO = <span class="hljs-string">&apos;BAR&apos;</span>;

<span class="hljs-keyword">import</span> { bar }  <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;bar-lib&apos;</span>;
<span class="hljs-keyword">const</span> FOO = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./foo&apos;</span>);
<span class="hljs-keyword">const</span> BAZ = <span class="hljs-number">1</span>;
<span class="hljs-keyword">const</span> BAR = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./bar&apos;</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> defaultExport <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>;

<span class="hljs-keyword">const</span> FOO = <span class="hljs-string">&apos;BAR&apos;</span>;
<span class="hljs-keyword">import</span> defaultExport <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./foo&apos;</span>;
<span class="hljs-keyword">import</span> { bar }  <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;bar-lib&apos;</span>;

<span class="hljs-keyword">const</span> FOO = <span class="hljs-string">&apos;BAR&apos;</span>;
<span class="hljs-keyword">const</span> FOO = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./foo&apos;</span>);
<span class="hljs-keyword">const</span> BAR = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./bar&apos;</span>);

<span class="hljs-keyword">const</span> BAZ = <span class="hljs-number">1</span>;
</code></pre>
</li>
</ul>
<h1 id="&#x9017;&#x53F7;"><a name="&#x9017;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x9017;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>19. &#x9017;&#x53F7;</h1>
<ul>
<li><p><a href="#19.1">19.1</a> <a name="19.1"></a> &#x884C;&#x9996;&#x9017;&#x53F7;&#xFF1A;<strong>&#x4E0D;&#x9700;&#x8981;</strong>&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L63" target="_blank"><code>comma-style</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> story = [
    once
  , upon
  , aTime
];

<span class="hljs-keyword">const</span> hero = {
    firstName: <span class="hljs-string">&apos;Ada&apos;</span>
  , lastName: <span class="hljs-string">&apos;Lovelace&apos;</span>
  , birthYear: <span class="hljs-number">1815</span>
  , superPower: <span class="hljs-string">&apos;computers&apos;</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> story = [
  once,
  upon,
  aTime,
];

<span class="hljs-keyword">const</span> hero = {
  firstName: <span class="hljs-string">&apos;Ada&apos;</span>,
  lastName: <span class="hljs-string">&apos;Lovelace&apos;</span>,
  birthYear: <span class="hljs-number">1815</span>,
  superPower: <span class="hljs-string">&apos;computers&apos;</span>,
};
</code></pre>
</li>
<li><p><a href="#19.2">19.2</a> <a name="19.2"></a> &#x589E;&#x52A0;&#x7ED3;&#x5C3E;&#x7684;&#x9017;&#x53F7;: <strong>&#x9700;&#x8981;</strong>&#x3002;eslint&#xFF1A;<a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js/#L49" target="_blank"><code>comma-dangle</code></a></p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;? &#x8FD9;&#x4F1A;&#x8BA9; git diffs &#x66F4;&#x5E72;&#x51C0;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x50CF; babel &#x8FD9;&#x6837;&#x7684;&#x8F6C;&#x8BD1;&#x5668;&#x4F1A;&#x79FB;&#x9664;&#x7ED3;&#x5C3E;&#x591A;&#x4F59;&#x7684;&#x9017;&#x53F7;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x4F60;&#x4E0D;&#x5FC5;&#x62C5;&#x5FC3;&#x8001;&#x65E7;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x5C3E;&#x9017;&#x53F7;&#x95EE;&#x9898;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//  git diff without trailing comma</span>
<span class="hljs-keyword">const</span> hero = {
     firstName: <span class="hljs-string">&apos;Florence&apos;</span>,
     lastName: <span class="hljs-string">&apos;Nightingale&apos;</span>
     lastName: <span class="hljs-string">&apos;Nightingale&apos;</span>,
     inventorOf: [<span class="hljs-string">&apos;coxcomb graph&apos;</span>, <span class="hljs-string">&apos;modern nursing&apos;</span>]
}

<span class="hljs-keyword">const</span> hero = {
  firstName: <span class="hljs-string">&apos;Dana&apos;</span>,
  lastName: <span class="hljs-string">&apos;Scully&apos;</span>
};

<span class="hljs-keyword">const</span> heroes = [
  <span class="hljs-string">&apos;Batman&apos;</span>,
  <span class="hljs-string">&apos;Superman&apos;</span>
];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> hero = {
     firstName: <span class="hljs-string">&apos;Florence&apos;</span>,
     lastName: <span class="hljs-string">&apos;Nightingale&apos;</span>,
     inventorOf: [<span class="hljs-string">&apos;coxcomb chart&apos;</span>, <span class="hljs-string">&apos;modern nursing&apos;</span>],
}

<span class="hljs-keyword">const</span> hero = {
  firstName: <span class="hljs-string">&apos;Dana&apos;</span>,
  lastName: <span class="hljs-string">&apos;Scully&apos;</span>,
};

<span class="hljs-keyword">const</span> heroes = [
  <span class="hljs-string">&apos;Batman&apos;</span>,
  <span class="hljs-string">&apos;Superman&apos;</span>,
];
</code></pre>
</li>
<li><p><a href="#19.3">19.3</a> <a name="19.3"></a> &#x907F;&#x514D;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x64CD;&#x4F5C;&#x7B26;,&#x5728;for&#x8BED;&#x53E5;&#x7684;&#x521D;&#x59CB;&#x5316;&#x6216;&#x66F4;&#x65B0;&#x90E8;&#x5206;&#x6216;&#x5982;&#x679C;&#x8868;&#x8FBE;&#x5F0F;&#x5E8F;&#x5217;&#x660E;&#x786E;&#x5730;&#x5305;&#x542B;&#x5728;&#x62EC;&#x53F7;&#x4E2D;&#x65F6;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x8FD0;&#x7B97;&#x7B26;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L317" target="_blank"><code>no-sequences</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> testA = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> testB = <span class="hljs-number">0</span>;
testA = testB += <span class="hljs-number">5</span>, testA + testB;
<span class="hljs-keyword">while</span> (testA = next(), testA &amp;&amp; testA.length) {}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo = (doSomething(), val);
(<span class="hljs-number">0</span>, <span class="hljs-built_in">eval</span>)(<span class="hljs-string">&quot;doSomething();&quot;</span>);
<span class="hljs-keyword">do</span> {} <span class="hljs-keyword">while</span> ((doSomething(), !!test));
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>, j = <span class="hljs-number">10</span>; i &lt; j; i++, j--) {}
</code></pre>
</li>
<li><p><a href="#19.4">19.4</a> <a name="19.4"></a> &#x7981;&#x6B62;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x9017;&#x53F7;&#x6765;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L128" target="_blank"><code>no-sparse-arrays</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = [,];
<span class="hljs-keyword">const</span> colors = [<span class="hljs-string">&apos;red&apos;</span>,, <span class="hljs-string">&apos;blue&apos;</span>];
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = [];
<span class="hljs-keyword">const</span> colors = [<span class="hljs-string">&apos;red&apos;</span>, <span class="hljs-string">&apos;blue&apos;</span>];
</code></pre>
</li>
</ul>
<h1 id="&#x5206;&#x53F7;"><a name="&#x5206;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x5206;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>20. &#x5206;&#x53F7;</h1>
<ul>
<li><p><a href="#20.1">20.1</a> <a name="20.1"></a> <strong>&#x4F7F;&#x7528;&#x5206;&#x53F7;</strong> &#x4E0D;&#x5141;&#x8BB8;&#x7701;&#x7565;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L538" target="_blank"><code>semi</code></a> eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L137" target="_blank"><code>no-unexpected-multiline</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> name = <span class="hljs-string">&apos;Skywalker&apos;</span>
  <span class="hljs-keyword">return</span> name
})()
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">(() =&gt; {
  <span class="hljs-keyword">const</span> name = <span class="hljs-string">&apos;Skywalker&apos;</span>;
  <span class="hljs-keyword">return</span> name;
})();

<span class="hljs-comment">// &#x9632;&#x6B62;&#x51FD;&#x6570;&#x5728;&#x4E24;&#x4E2A; IIFE &#x5408;&#x5E76;&#x65F6;&#x88AB;&#x5F53;&#x6210;&#x4E00;&#x4E2A;&#x53C2;&#x6570;</span>
;(() =&gt; {
  <span class="hljs-keyword">const</span> name = <span class="hljs-string">&apos;Skywalker&apos;</span>;
  <span class="hljs-keyword">return</span> name;
})();
</code></pre>
</li>
<li><p><a href="#20.2">20.2</a> <a name="20.2"></a> &#x5206;&#x53F7;&#x4E00;&#x5B9A;&#x51FA;&#x73B0;&#x5728;&#x53E5;&#x672B;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L546" target="_blank"><code>semi-style</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">foo()
;[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].forEach(bar)

<span class="hljs-keyword">for</span> (
    <span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>
    ; i &lt; <span class="hljs-number">10</span>
    ; i += <span class="hljs-number">1</span>
) {
    foo()
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">foo();
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].forEach(bar);

<span class="hljs-keyword">for</span> (
    <span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>;
    i &lt; <span class="hljs-number">10</span>;
    i += <span class="hljs-number">1</span>
) {
    foo();
}
</code></pre>
</li>
<li><p><a href="#20.3">20.3</a> <a name="20.3"></a> &#x4E0D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x591A;&#x4F59;&#x7684;&#x5206;&#x53F7;&#x3002; eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/errors.js#L89" target="_blank"><code>no-extra-semi</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x = <span class="hljs-number">5</span>;;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// code</span>
};
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x = <span class="hljs-number">5</span>;
<span class="hljs-keyword">const</span> foo = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// code</span>
};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// code</span>
}
</code></pre>
<p><a href="http://stackoverflow.com/a/7365214/1712802" target="_blank">Read more</a>.</p>
</li>
</ul>
<h1 id="&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><a name="&#x7C7B;&#x578B;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>21. &#x7C7B;&#x578B;&#x8F6C;&#x6362;</h1>
<ul>
<li><a href="#21.1">21.1</a> <a name="21.1"></a> &#x5728;&#x8BED;&#x53E5;&#x5F00;&#x59CB;&#x65F6;&#x6267;&#x884C;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3002;</li>
<li><p><a href="#21.2">21.2</a> <a name="21.2"></a> &#x5B57;&#x7B26;&#x4E32;&#xFF1A;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//  =&gt; this.reviewScore = 9;</span>

<span class="hljs-keyword">const</span> totalScore = <span class="hljs-keyword">new</span> <span class="hljs-built_in">String</span>(<span class="hljs-keyword">this</span>.reviewScore); <span class="hljs-comment">// typeof totalScore is &quot;object&quot; not &quot;string&quot;</span>

<span class="hljs-keyword">const</span> totalScore = <span class="hljs-keyword">this</span>.reviewScore + <span class="hljs-string">&apos;&apos;</span>; <span class="hljs-comment">// invokes this.reviewScore.valueOf()</span>

<span class="hljs-keyword">const</span> totalScore = <span class="hljs-keyword">this</span>.reviewScore.toString(); <span class="hljs-comment">// isn&#x2019;t guaranteed to return a string</span>
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//  =&gt; this.reviewScore = 9;</span>

<span class="hljs-keyword">const</span> totalScore = <span class="hljs-built_in">String</span>(<span class="hljs-keyword">this</span>.reviewScore);
</code></pre>
</li>
<li><p><a href="#21.3">21.3</a> <a name="21.3"></a> &#x5BF9;&#x6570;&#x5B57;&#x4F7F;&#x7528; <code>parseInt</code> &#x8F6C;&#x6362;&#xFF0C;&#x5E76;&#x5E26;&#x4E0A;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x7684;&#x57FA;&#x6570;&#x3002;eslint: <a href="http://gitlab.iwhalecloud.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/best-practices.js#L391" target="_blank"><code>radix</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> inputValue = <span class="hljs-string">&apos;4&apos;</span>;

<span class="hljs-keyword">const</span> val = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Number</span>(inputValue);

<span class="hljs-keyword">const</span> val = +inputValue;

<span class="hljs-keyword">const</span> val = inputValue &gt;&gt; <span class="hljs-number">0</span>;

<span class="hljs-keyword">const</span> val = <span class="hljs-built_in">parseInt</span>(inputValue);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> inputValue = <span class="hljs-string">&apos;4&apos;</span>;

<span class="hljs-keyword">const</span> val = <span class="hljs-built_in">Number</span>(inputValue);

<span class="hljs-keyword">const</span> val = <span class="hljs-built_in">parseInt</span>(inputValue, <span class="hljs-number">10</span>);
</code></pre>
</li>
<li><p><a href="#21.5">21.5</a> <a name="21.5"></a> &#x7981;&#x6B62;&#x4F7F;&#x7528;&#x4F4D;&#x64CD;&#x4F5C;&#x8FD0;&#x7B97;&#x7B26;. eslint: <code>no-bitwise</code>(<a href="https://eslint.org/docs/rules/no-bitwise" target="_blank">https://eslint.org/docs/rules/no-bitwise</a>)</p>
<blockquote>
<p>&#x5F53;&#x4F60;&#x4F7F;&#x7528;&#x4F4D;&#x8FD0;&#x7B97;&#x7684;&#x65F6;&#x5019;&#x8981;&#x5C0F;&#x5FC3;&#x3002; &#x6570;&#x5B57;&#x603B;&#x662F;&#x88AB;&#x4EE5; 64-bit &#x503C; &#x7684;&#x5F62;&#x5F0F;&#x8868;&#x793A;&#xFF0C;&#x4F46;&#x662F;&#x4F4D;&#x8FD0;&#x7B97;&#x603B;&#x662F;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A; 32-bit &#x7684;&#x6574;&#x6570;&#x3002; &#x5BF9;&#x4E8E;&#x5927;&#x4E8E; 32 &#x4F4D;&#x7684;&#x6574;&#x6570;&#x503C;&#xFF0C;&#x4F4D;&#x8FD0;&#x7B97;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x610F;&#x5916;&#x884C;&#x4E3A;&#x3002; &#x6700;&#x5927;&#x7684; 32 &#x4F4D;&#x6574;&#x6570;&#x662F;&#xFF1A; 2,147,483,647&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = y | z;
<span class="hljs-keyword">var</span> test = y &amp; z;
x |= y;
x &amp;= y;
<span class="hljs-keyword">var</span> test = y ^ z;
<span class="hljs-keyword">var</span> test = ~ z;
<span class="hljs-keyword">var</span> test = y &lt;&lt; z;
<span class="hljs-keyword">var</span> test = y &gt;&gt; z;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> test = y || z;
<span class="hljs-keyword">var</span> test = y &amp;&amp; z;
<span class="hljs-keyword">var</span> test = y &gt; z;
<span class="hljs-keyword">var</span> test = y &lt; z;
test += y;
</code></pre>
</li>
<li><p><a href="#21.6">21.6</a> <a name="21.6"></a> &#x5E03;&#x5C14;:</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> age = <span class="hljs-number">0</span>;

<span class="hljs-keyword">const</span> hasAge = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Boolean</span>(age);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> age = <span class="hljs-number">0</span>;

<span class="hljs-keyword">const</span> hasAge = <span class="hljs-built_in">Boolean</span>(age);

<span class="hljs-keyword">const</span> hasAge = !!age;
</code></pre>
</li>
</ul>
<h1 id="&#x547D;&#x540D;&#x89C4;&#x5219;"><a name="&#x547D;&#x540D;&#x89C4;&#x5219;" class="anchor-navigation-ex-anchor" href="#&#x547D;&#x540D;&#x89C4;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>22. &#x547D;&#x540D;&#x89C4;&#x5219;</h1>
<ul>
<li><p><a href="#22.1">22.1</a> <a name="22.1"></a> &#x907F;&#x514D;&#x5355;&#x5B57;&#x6BCD;&#x547D;&#x540D;&#x3002;&#x547D;&#x540D;&#x5E94;&#x5177;&#x5907;&#x63CF;&#x8FF0;&#x6027;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x4E0D;&#x62A5;&#x9519;&#x4F46;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">q</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ...stuff...</span>
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">query</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// ..stuff..</span>
}
</code></pre>
</li>
<li><p><a href="#22.2">22.2</a> <a name="22.2"></a> &#x4F7F;&#x7528;&#x5C0F;&#x9A7C;&#x5CF0;&#x5F0F;&#x547D;&#x540D;&#x5BF9;&#x8C61;&#x3001;&#x51FD;&#x6570;&#x548C;&#x5B9E;&#x4F8B;&#x3002;eslint: <a href="http://gitlab.ztesoft.com/fish-x/eslint-config-whalecloud/blob/issue%231/rules/style.js#L28" target="_blank"><code>camelcase</code></a></p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> OBJEcttsssss = {};
<span class="hljs-keyword">const</span> this_is_my_object = {};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">c</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> thisIsMyObject = {};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">thisIsMyFunction</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
</li>
<li><p><a href="#22.3">22.3</a> <a name="22.3"></a> &#x4F7F;&#x7528;&#x5E15;&#x65AF;&#x5361;&#x5F0F;&#x547D;&#x540D;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6216;&#x7C7B;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">user</span>(<span class="hljs-params">options</span>) </span>{
  <span class="hljs-keyword">this</span>.name = options.name;
}

<span class="hljs-keyword">const</span> bad = <span class="hljs-keyword">new</span> user({
  name: <span class="hljs-string">&apos;nope&apos;</span>,
});
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> </span>{
  <span class="hljs-keyword">constructor</span>(options) {
    <span class="hljs-keyword">this</span>.name = options.name;
  }
}

<span class="hljs-keyword">const</span> good = <span class="hljs-keyword">new</span> User({
  name: <span class="hljs-string">&apos;yup&apos;</span>,
});
</code></pre>
</li>
<li><p><a href="#22.4">22.4</a> <a name="22.4"></a> &#x522B;&#x4FDD;&#x5B58; <code>this</code> &#x7684;&#x5F15;&#x7528;&#x3002;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6216; Function#bind&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> self = <span class="hljs-keyword">this</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(self);
  };
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> that = <span class="hljs-keyword">this</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(that);
  };
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> () =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
  };
}
</code></pre>
</li>
<li><p><a href="#22.5">22.5</a> <a name="22.5"></a> &#x5982;&#x679C;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x53EA;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x90A3;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x5FC5;&#x987B;&#x548C;&#x7C7B;&#x540D;&#x5B8C;&#x5168;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// file contents</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheckBox</span> </span>{
  <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> CheckBox;

<span class="hljs-keyword">import</span> CheckBox <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./checkBox&apos;</span>;

<span class="hljs-keyword">import</span> CheckBox <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./check_box&apos;</span>;
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// file contents</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheckBox</span> </span>{
  <span class="hljs-comment">// ...</span>
}
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> CheckBox;

<span class="hljs-keyword">import</span> CheckBox <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./CheckBox&apos;</span>;
</code></pre>
</li>
<li><p><a href="#22.6">22.6</a> <a name="22.6"></a> &#x5F53;&#x4F60;&#x5BFC;&#x51FA;&#x9ED8;&#x8BA4;&#x7684;&#x51FD;&#x6570;&#x65F6;&#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x5F0F;&#x547D;&#x540D;&#x3002;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x5FC5;&#x987B;&#x548C;&#x51FD;&#x6570;&#x540D;&#x5B8C;&#x5168;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">makeStyleGuide</span>(<span class="hljs-params"></span>) </span>{
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> makeStyleGuide;
</code></pre>
</li>
<li><p><a href="#22.7">22.7</a> <a name="22.7"></a> &#x5F53;&#x4F60;&#x5BFC;&#x51FA;&#x5355;&#x4F8B;&#x3001;&#x51FD;&#x6570;&#x5E93;&#x3001;&#x7A7A;&#x5BF9;&#x8C61;&#x65F6;&#x4F7F;&#x7528;&#x5E15;&#x65AF;&#x5361;&#x5F0F;&#x547D;&#x540D;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> AirbnbStyleGuide = {
  es6: {
  }
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> AirbnbStyleGuide;
</code></pre>
</li>
</ul>
<h1 id="&#x5B58;&#x53D6;&#x5668;"><a name="&#x5B58;&#x53D6;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x5B58;&#x53D6;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>23. &#x5B58;&#x53D6;&#x5668;</h1>
<ul>
<li><a href="#23.1">23.1</a> <a name="23.1"></a> &#x5BF9;&#x4E8E;&#x5C5E;&#x6027;&#x7684;&#x5B58;&#x53D6;&#x51FD;&#x6570;&#x4E0D;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;</li>
<li><p><a href="#23.2">23.2</a> <a name="23.2"></a> &#x5982;&#x679C;&#x4F60;&#x9700;&#x8981;&#x5B58;&#x53D6;&#x51FD;&#x6570;&#x65F6;&#x4F7F;&#x7528; <code>getVal()</code> &#x548C; <code>setVal(&apos;hello&apos;)</code>&#x3002;</p>
<blockquote>
<p>&#x4E0D;&#x8981;&#x4F7F;&#x7528; JavaScript &#x7684; getters/setters &#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x4F1A;&#x5BFC;&#x81F4;&#x610F;&#x5916;&#x7684;&#x526F;&#x4F5C;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x66F4;&#x52A0;&#x96BE;&#x4EE5;&#x6D4B;&#x8BD5;&#x3001;&#x7EF4;&#x62A4;&#x548C;&#x63A8;&#x6572;&#x3002;</p>
</blockquote>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript">dragon.age();

dragon.age(<span class="hljs-number">25</span>);
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript">dragon.getAge();

dragon.setAge(<span class="hljs-number">25</span>);
</code></pre>
</li>
<li><p><a href="#23.3">23.3</a> <a name="23.3"></a> &#x5982;&#x679C;&#x5C5E;&#x6027;&#x662F;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x4F7F;&#x7528; <code>isVal()</code> &#x6216; <code>hasVal()</code>&#x3002;</p>
<p><strong><font color="red">&#x53CD;&#x4F8B;</font></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (!dragon.age()) {
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}
</code></pre>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (!dragon.hasAge()) {
  <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}
</code></pre>
</li>
<li><p><a href="#23.4">23.4</a> <a name="23.4"></a> &#x521B;&#x5EFA; <code>get()</code> &#x548C; <code>set()</code> &#x51FD;&#x6570;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#xFF0C;&#x4F46;&#x8981;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
<p><strong>&#x6B63;&#x4F8B;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Jedi</span> </span>{
  <span class="hljs-keyword">constructor</span>(options = {}) {
    <span class="hljs-keyword">const</span> lightsaber = options.lightsaber || <span class="hljs-string">&apos;blue&apos;</span>;
    <span class="hljs-keyword">this</span>.set(<span class="hljs-string">&apos;lightsaber&apos;</span>, lightsaber);
  }

  set(key, val) {
    <span class="hljs-keyword">this</span>[key] = val;
  }

  get(key) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>[key];
  }
}
</code></pre>
</li>
</ul>
<h1 id="&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;"><a name="&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>24. &#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x548C;&#x65B9;&#x6CD5;</h1>
<p>  <code>FishX</code> &#x5C01;&#x88C5;&#x7684;&#x4E00;&#x5957;&#x81EA;&#x5DF1;&#x7684; <code>eslint</code> &#x4EE3;&#x7801;&#x68C0;&#x6D4B;&#x89C4;&#x5219;&#xFF0C;&#x8FD9;&#x4E9B;&#x89C4;&#x5219;&#x90FD;&#x662F;&#x6309;&#x7167;&#x4EE5;&#x4E0A;&#x7684;&#x7F16;&#x7A0B;&#x89C4;&#x8303;&#x6765;&#x5236;&#x5B9A;&#x7684;&#x3002;</p>
<h2 id="&#x5B89;&#x88C5;"><a name="&#x5B89;&#x88C5;" class="anchor-navigation-ex-anchor" href="#&#x5B89;&#x88C5;"><i class="fa fa-link" aria-hidden="true"></i></a>24.1. &#x5B89;&#x88C5;</h2>
<ul>
<li><p>&#x5168;&#x5C40;&#x4F7F;&#x7528;
&#x5982;&#x679C;&#x60F3;&#x5728;&#x5168;&#x5C40;&#x4F7F;&#x7528; <code>fishx lint</code> &#x53EF;&#x4EE5;&#x5168;&#x5C40;&#x5B89;&#x88C5;&#xFF1A;</p>
<pre><code class="lang-bash">$ npm install -g @fishx/cli
</code></pre>
</li>
<li><p>&#x9879;&#x76EE;&#x4E2D;&#x4F7F;&#x7528;&#xFF1A;</p>
<pre><code class="lang-bash">$ npm install @fishx/cli
</code></pre>
</li>
</ul>
<h2 id="&#x4F7F;&#x7528;"><a name="&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>24.2. &#x4F7F;&#x7528;</h2>
<ul>
<li><p>&#x5BF9;&#x63D0;&#x4EA4;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x6821;&#x9A8C;</p>
<p>&#x5728; <code>package.json</code> &#x6587;&#x4EF6;&#x7684; <code>scripts</code> &#x4E2D;&#x6DFB;&#x52A0;:</p>
<pre><code class="lang-json">+ <span class="hljs-string">&quot;husky&quot;</span>: {
+    <span class="hljs-string">&quot;hooks&quot;</span>: {
+        <span class="hljs-string">&quot;pre-commit&quot;</span>: <span class="hljs-string">&quot;fishx lint --eslint --staged&quot;</span>
+     }
+ }
</code></pre>
<p>&#x5728;&#x6BCF;&#x6B21; <code>commit</code> &#x4EE3;&#x7801;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x5BF9;&#x63D0;&#x4EA4;&#x5230;&#x6682;&#x5B58;&#x533A;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x6821;&#x9A8C;&#xFF1A;</p>
<p><img src="picture/eslint-husky.png" alt="fishx-mobile-router"></p>
</li>
<li><p>&#x4F7F;&#x7528; <code>dir</code> &#x53C2;&#x6570;&#x81EA;&#x5B9A;&#x4E49;&#x6307;&#x5B9A;&#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x68C0;&#x6D4B;&#x4F60;&#x6240;&#x6307;&#x5B9A;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709; <code>js</code> &#x6587;&#x4EF6;&#xFF08;&#x4E0D;&#x9012;&#x5F52;&#x68C0;&#x6D4B;&#xFF0C;&#x53EA;&#x68C0;&#x6D4B;&#x6307;&#x5B9A;&#x7684;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>js</code>&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x786E;&#x4FDD;&#x4F60;&#x6307;&#x5B9A;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#x5B58;&#x5728; <code>js</code> &#x6587;&#x4EF6;&#x3002;</p>
<pre><code class="lang-bash">$ fishx lint --eslint <span class="hljs-string">&apos;/Users/qifutao/Documents/workspace/fishx-desktop-pro/src/pages/AppMgr/*.js&apos;</span>
</code></pre>
<p>&#x68C0;&#x6D4B;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;&#x5B50;&#x76EE;&#x5F55;&#x4E2D;&#x7684; <code>js</code> &#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-bash">$ fishx lint --eslint <span class="hljs-string">&apos;/Users/qifutao/Documents/workspace/fishx-desktop-pro/src/**/*.js&apos;</span>
</code></pre>
<p>&#x6307;&#x5B9A;&#x591A;&#x4E2A;&#x8981;&#x68C0;&#x6D4B;&#x7684; <code>js</code> &#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF0C;&#x591A;&#x4E2A;&#x8DEF;&#x5F84;&#x4E4B;&#x95F4;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x8FDB;&#x884C;&#x5206;&#x9694;&#xFF1A;</p>
<pre><code class="lang-bash">$ fishx lint --eslint <span class="hljs-string">&apos;/Users/qifutao/Documents/workspace/fishx-desktop-pro/src/pages/AppMgr/**/*.js,/Users/qifutao/Documents/workspace/fishx-desktop-pro/src/pages/Button/**/*.js,/Users/qifutao/Documents/workspace/fishx-desktop-pro/src/pages/Login/**/*.js&apos;</span>
</code></pre>
<p>&#x652F;&#x6301;&#x6307;&#x5B9A;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x8FDB;&#x884C;&#x68C0;&#x6D4B;</p>
<pre><code class="lang-bash">$ fishx lint --eslint <span class="hljs-string">&apos;src/pages&apos;</span>
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528; <code>--format</code> &#x53C2;&#x6570;&#x6307;&#x5B9A;&#x63A7;&#x5236;&#x53F0;&#x7684;&#x8F93;&#x51FA;&#x683C;&#x5F0F;
&#x76EE;&#x524D;&#x652F;&#x6301;&#x7684;&#x8F93;&#x51FA;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>checkstyle</li>
<li>codeframe</li>
<li>compact</li>
<li>html</li>
<li>jslint-xml</li>
<li>json</li>
<li>junit</li>
<li>stylish <strong>(&#x9ED8;&#x8BA4;)</strong></li>
<li>table</li>
<li>tap</li>
<li>unix</li>
<li>visualstudio</li>
</ul>
<p>&#x4E3E;&#x4E2A;&#x1F330;&#xFF1A;</p>
<pre><code class="lang-bash">$ fishx lint --eslint --format=table <span class="hljs-string">&apos;src/pages&apos;</span>
</code></pre>
<p>&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#x683C;&#x5F0F;&#xFF1A;
<img src="picture/eslint-format.png" alt="fishx-mobile-router"></p>
</li>
<li><p>&#x914D;&#x7F6E;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6587;&#x4EF6;</p>
<p>&#x4F7F;&#x7528;&#x7F16;&#x8F91;&#x5668;&#x5728;&#x8981;&#x68C0;&#x6D4B;&#x7684;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA; <code>.eslintignore</code> &#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x8BE5;&#x6587;&#x4EF6;&#x4E2D;&#x914D;&#x7F6E;&#x9700;&#x8981;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x7684;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF0C;&#x4E00;&#x884C;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#xFF0C;&#x4F8B;&#x5982;&#x4EE5;&#x4E0B;&#x5C31;&#x662F;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6240;&#x6709;&#x7684;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code>  **/*.js
</code></pre><p>&#x5F53; <code>ESLint</code> &#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x5728;&#x786E;&#x5B9A;&#x54EA;&#x4E9B;&#x6587;&#x4EF6;&#x8981;&#x68C0;&#x6D4B;&#x4E4B;&#x524D;&#xFF0C;&#x5B83;&#x4F1A;&#x5728;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E2D;&#x67E5;&#x627E;&#x4E00;&#x4E2A; <code>.eslintignore</code> &#x6587;&#x4EF6;&#x3002;&#x5982;&#x679C;&#x53D1;&#x73B0;&#x4E86;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5F53;&#x904D;&#x5386;&#x76EE;&#x5F55;&#x65F6;&#xFF0C;&#x5C06;&#x4F1A;&#x5E94;&#x7528;&#x8FD9;&#x4E9B;&#x504F;&#x597D;&#x8BBE;&#x7F6E;&#x3002;&#x4E00;&#x6B21;&#x53EA;&#x6709;&#x4E00;&#x4E2A; <code>.eslintignore</code> &#x6587;&#x4EF6;&#x4F1A;&#x88AB;&#x4F7F;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x4E0D;&#x662F;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>.eslintignore</code> &#x6587;&#x4EF6;&#x5C06;&#x4E0D;&#x4F1A;&#x88AB;&#x7528;&#x5230;&#x3002;&#x8BE5;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x5199;&#x6CD5;&#x9075;&#x5FAA;&#x4E86; <code>glob</code> &#x8BED;&#x6CD5;&#xFF1A;</p>
<ul>
<li>*:&#x5339;&#x914D;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#x90E8;&#x5206;&#x4E2D;0&#x6216;&#x591A;&#x4E2A;&#x5B57;&#x7B26;, &#x6CE8;&#x610F;&#x4E0D;&#x5339;&#x914D;&#x4EE5;.&#x5F00;&#x59CB;&#x7684;&#x8DEF;&#x5F84;,&#x6BD4;&#x5982;.a</li>
<li>**: &#x5339;&#x914D;0&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x5B50;&#x6587;&#x4EF6;&#x5939;</li>
<li>?:&#x5339;&#x914D;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;</li>
<li>{a,b}: &#x5339;&#x914D;a&#x6216;&#x8005;b, a&#x548C;b&#x4E5F;&#x662F;&#x901A;&#x914D;&#x7B26;,&#x53EF;&#x4EE5;&#x7531;&#x5176;&#x4ED6;&#x901A;&#x914D;&#x7B26;&#x7EC4;&#x6210;</li>
<li>!: &#x6392;&#x9664;&#x6587;&#x4EF6;,&#x5982;!a.js&#x8868;&#x793A;&#x6392;&#x9664;&#x6587;&#x4EF6;a.js</li>
</ul>
<p>&#x683C;&#x5F0F;&#x89C4;&#x8303;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>&#x4EE5; # &#x5F00;&#x5934;&#x7684;&#x884C;&#x88AB;&#x5F53;&#x4F5C;&#x6CE8;&#x91CA;&#xFF0C;&#x4E0D;&#x5F71;&#x54CD;&#x5FFD;&#x7565;&#x6A21;&#x5F0F;&#x3002;</li>
<li>&#x8DEF;&#x5F84;&#x662F;&#x76F8;&#x5BF9;&#x4E8E; .eslintignore &#x7684;&#x4F4D;&#x7F6E;&#x6216;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x3002;</li>
<li>&#x5FFD;&#x7565;&#x6A21;&#x5F0F;&#x540C; .gitignore &#x89C4;&#x8303;&#x3002;</li>
<li>&#x4EE5; ! &#x5F00;&#x5934;&#x7684;&#x884C;&#x662F;&#x5426;&#x5B9A;&#x6A21;&#x5F0F;&#xFF0C;&#x5B83;&#x5C06;&#x4F1A;&#x91CD;&#x65B0;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x4E4B;&#x524D;&#x88AB;&#x5FFD;&#x7565;&#x7684;&#x6A21;&#x5F0F;&#x3002;</li>
<li>&#x9664;&#x4E86; .eslintignore &#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;ESLint&#x603B;&#x662F;&#x5FFD;&#x7565; /node_modules/<em> &#x548C; /bower_components/</em> &#x4E2D;&#x7684;&#x6587;&#x4EF6;&#x3002;</li>
</ul>
<p>&#x4F8B;&#x5982;&#x4EE5;&#x4E0B;&#x5199;&#x6CD5;&#xFF0C;&#x5C31;&#x662F;&#x9996;&#x5148;&#x5FFD;&#x7565;&#x6240;&#x6709; js ,&#x7136;&#x540E;&#x53BB;&#x9664;&#x5FFD;&#x7565; <code>code/portal/src/main/webapp/modules/</code> &#x4E0B;&#x7684;&#x6240;&#x6709;js &#xFF0C;&#x6700;&#x7EC8;&#x53EF;&#x4EE5;&#x8FBE;&#x5230;&#x6307;&#x5B9A;&#x68C0;&#x6D4B;&#x8BE5;&#x76EE;&#x5F55;&#x4E2D; js &#x7684;&#x6548;&#x679C;&#xFF1A;</p>
<pre><code>**/*js
!code/portal/src/main/webapp/modules/**/*.js
</code></pre></li>
<li><p>&#x4F7F;&#x7528; <code>--prettier</code> &#x4EE3;&#x7801;&#x7F8E;&#x5316;</p>
<ul>
<li><p>&#x5BF9;&#x63D0;&#x4EA4;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x7F8E;&#x5316;</p>
<pre><code class="lang-bash">$ fishx lint --prettier --staged
</code></pre>
</li>
<li><p>&#x5BF9;&#x6307;&#x5B9A;&#x8DEF;&#x5F84;&#x4E0B;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x7F8E;&#x5316;</p>
<pre><code class="lang-bash">$ fishx lint --prettier <span class="hljs-string">&apos;src/&apos;</span>
</code></pre>
</li>
</ul>
</li>
<li><p>&#x4F7F;&#x7528; <code>--format</code> &#x5BF9;&#x4EE3;&#x7801;&#x81EA;&#x52A8;&#x4FEE;&#x590D;</p>
<p>&#x6267;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x5BF9;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x4FEE;&#x590D;</p>
<ul>
<li><p>&#x5BF9;&#x63D0;&#x4EA4;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4FEE;&#x590D;</p>
<pre><code class="lang-bash">$ fishx lint --eslint --fix --staged
</code></pre>
</li>
<li><p>&#x5BF9;&#x6307;&#x5B9A;&#x8DEF;&#x5F84;&#x4E0B;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4FEE;&#x590D;</p>
<pre><code class="lang-bash">$ fishx lint --eslint --fix <span class="hljs-string">&apos;src/pages&apos;</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h2 id="&#x53C2;&#x6570;&#x8BF4;&#x660E;"><a name="&#x53C2;&#x6570;&#x8BF4;&#x660E;" class="anchor-navigation-ex-anchor" href="#&#x53C2;&#x6570;&#x8BF4;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>24.3. &#x53C2;&#x6570;&#x8BF4;&#x660E;</h2>
<pre><code class="lang-bash">$ Usage: fishx-lint [options] [dir]

<span class="hljs-comment"># &#x5BF9;&#x6307;&#x5B9A;&#x8DEF;&#x5F84; lint</span>
fishx-lint --eslint <span class="hljs-string">&apos;src/&apos;</span>

<span class="hljs-comment"># &#x53EA;&#x5BF9;&#x63D0;&#x4EA4;&#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C; lint</span>
fishx-lint --staged --eslint

Flags:
--staged, -S              only lint git staged files                          [boolean] [default: <span class="hljs-literal">false</span>]
--prettier, -p            format code with prettier                           [boolean] [default: <span class="hljs-literal">false</span>]
--eslint, <span class="hljs-_">-e</span>              <span class="hljs-built_in">enable</span> lint javascript                              [boolean] [default: <span class="hljs-literal">false</span>]
--fix, <span class="hljs-_">-f</span>                 fix all eslint and stylelint auto-fixable problems  [boolean] [default: <span class="hljs-literal">false</span>]
--format, -F              output format of console                            [string]  [default: stylish]
--cwd, -c                 current working directory                           [default: process.cwd()]
</code></pre>
<p><strong>&#x66F4;&#x591A;&#x4EE3;&#x7801;&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x7684;&#x4F7F;&#x7528;&#x7EC6;&#x8282;&#x53EF;&#x4EE5;&#x53C2;&#x8003;<a href="https://fish.iwhalecloud.com/fishx-desktop/fishx/docs/eslint/basic" target="_blank">&#x4EE3;&#x7801;&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x7AE0;&#x8282;</a>&#x3002;</strong></p>
<h2 id="&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;cicd&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;"><a name="&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;cicd&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;cicd&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>24.4. &#x5982;&#x4F55;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;CI/CD&#x68C0;&#x6D4B;&#x6D41;&#x7A0B;</h2>
<ol>
<li><p>&#x8FDB;&#x5165;ZCM&#xFF08;10.45.80.26/portal&#xFF09;&#x5E76;&#x767B;&#x9646;&#xFF0C;&#x70B9;&#x51FB;&#x6709;&#x4E0A;&#x89D2;&#x83DC;&#x5355;&#x2014;&#x2014;&gt;&#x5F00;&#x53D1;&#x4E2D;&#x5FC3;&#x2014;&#x2014;&gt;&#x6301;&#x7EED;&#x6784;&#x5EFA;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</p>
<p><img src="picture/cicd1.png" alt="cicd1"></p>
</li>
<li><p>&#x8FDB;&#x5165;&#x6301;&#x7EED;&#x6784;&#x5EFA;&#x9875;&#x9762;&#x540E;&#x70B9;&#x51FB;&#x65B0;&#x5EFA;&#x6784;&#x5EFA;&#xFF0C;&#x8FDB;&#x5165;&#x65B0;&#x5EFA;&#x9875;&#x9762;&#x5982;&#x4E0B;&#x56FE;&#xFF0C;&#x914D;&#x7F6E;&#x81EA;&#x5DF1;&#x7684;&#x4EE3;&#x7801;&#x5F52;&#x5C5E;&#xFF0C;&#x5728;&#x8BED;&#x8A00;&#x6A21;&#x677F;&#x5904;&#x9009;&#x62E9;Java+Js&#xFF0C;&#x6700;&#x540E;&#x9009;&#x62E9;&#x8981;&#x6784;&#x5EFA;&#x7684;&#x7684;&#x955C;&#x50CF;&#xFF0C;&#x70B9;&#x51FB;next</p>
<p><img src="picture/cicd4.png" alt="cicd4"></p>
</li>
<li><p>&#x5728;&#x4EE5;&#x4E0B;&#x9875;&#x9762;&#x9009;&#x62E9;&#x4EA7;&#x54C1;&#x6A21;&#x5757;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#x9700;&#x8981;&#x7684;&#x4EA7;&#x54C1;&#x5219;&#x9700;&#x8981;&#x521B;&#x5EFA;&#x4EA7;&#x54C1;&#xFF0C;&#x5B8C;&#x6210;&#x540E;&#x70B9;&#x51FB;next&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;</p>
<p><img src="picture/cicd5.png" alt="cicd5"></p>
</li>
<li><p>&#x5728;&#x8BE5;&#x9875;&#x9762;&#x6253;&#x5F00;&#x201C;&#x662F;&#x5426;&#x9700;&#x8981;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x9009;&#x9879;&#x201D;&#xFF0C;&#x4E4B;&#x540E;&#x4E00;&#x76F4;&#x70B9;&#x51FB;next&#x5230;&#x6700;&#x540E;&#x4E00;&#x6B65;&#x70B9;&#x51FB;create</p>
<p><img src="picture/cicd6.png" alt="cicd6"></p>
</li>
<li><p>&#x5728;&#x5982;&#x4E0B;&#x754C;&#x9762;&#x4E2D;&#x7684;&#x70B9;&#x51FB;&#x201C;&#x4EE3;&#x7801;&#x4E0B;&#x8F7D;&#x201D;&#x9009;&#x9879;&#x914D;&#x7F6E;&#x4EE3;&#x7801;&#x4E0B;&#x8F7D;&#x7684;&#x7C7B;&#x578B;&#x3001;&#x8DEF;&#x5F84;&#x3001;&#x7528;&#x6237;&#x540D;&#x3001;&#x5BC6;&#x7801;&#x548C;&#x8981;&#x4E0B;&#x8F7D;&#x7684;&#x5206;&#x652F;&#xFF0C;&#x914D;&#x7F6E;&#x5B8C;&#x6210;&#x540E;&#x70B9;&#x51FB;&#x201C;save&quot;&#x4FDD;&#x5B58;&#x5373;&#x521B;&#x5EFA;&#x5B8C;&#x6210;</p>
<p><img src="picture/cicd7.png" alt="cicd7"></p>
</li>
<li><p>&#x914D;&#x7F6E;&#x4F8B;&#x5916;&#x6587;&#x4EF6;&#x5E76;&#x6253;&#x5F00;es6&#x68C0;&#x6D4B;&#x914D;&#x7F6E;&#x9879;&#xFF0C;&#x9996;&#x5148;&#x9700;&#x8981;&#x5728;&#x9879;&#x76EE;&#x7684;CI_Config&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;.eslintignore&#x6587;&#x4EF6;&#xFF0C;&#x5176;&#x5199;&#x6CD5;&#x53C2;&#x89C1;&#x201C;&#x914D;&#x7F6E;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x201D;&#x90E8;&#x5206;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x5982;&#x4E0B;&#x754C;&#x9762;&#x4E2D;&#x7684;&#x70B9;&#x51FB;&#x201C;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x201D;&#x9009;&#x9879;&#xFF0C;&#x5C06;&#x5176;&#x4E2D;&#x4F8B;&#x5916;&#x8DEF;&#x5F84;&#x914D;&#x7F6E;&#x4E3A;CI_Config&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x586B;&#x9ED8;&#x8BA4;CI_Config&#x5728;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x5E76;&#x4E14;&#x6253;&#x5F00;es6&#x68C0;&#x6D4B;&#x914D;&#x7F6E;&#x9879;&#xFF0C;&#x5B8C;&#x6210;&#x540E;&#x70B9;&#x51FB;&#x201C;save&quot;&#x4FDD;&#x5B58;&#x5373;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#xFF0C;&#x4E0B;&#x9762;&#x4EE5;ngportal&#x4E3A;&#x4F8B;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF1A;</p>
<ul>
<li>&#x9996;&#x5148;&#x8FDB;&#x5165;ngportal&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x7684;CI_Config&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;.eslintignore&#x6587;&#x4EF6;&#x3002;</li>
</ul>
<p><img src="picture/ngportal1.png" alt="ngportal1"></p>
<ul>
<li><p>&#x5728;.eslintignore&#x6587;&#x4EF6;&#x4E2D;&#x901A;&#x8FC7;&#x9996;&#x5148;&#x5FFD;&#x7565;&#x68C0;&#x6D4B;&#x6240;&#x6709;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x6307;&#x5B9A;&#x8981;&#x68C0;&#x6D4B;&#x7684;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x7684;&#x5F62;&#x5F0F;&#x8FBE;&#x5230;&#x6307;&#x5B9A;&#x68C0;&#x6D4B;&#x7279;&#x5B9A;&#x76EE;&#x5F55;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x6CE8;&#x610F;<code>*.js</code>&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x544A;&#x8BC9;&#x68C0;&#x6D4B;&#x5DE5;&#x5177;&#x4F60;&#x9700;&#x8981;&#x68C0;&#x6D4B;&#x7684;&#x662F;&#x8FD9;&#x4E2A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6240;&#x6709;js&#x6587;&#x4EF6;&#xFF0C;&#x5426;&#x5219;&#x4F60;&#x7684;&#x8BBE;&#x7F6E;&#x53EF;&#x80FD;&#x5931;&#x6548;&#x3002;</p>
<p><img src="picture/ngportal2.png" alt="ngportal2"></p>
</li>
<li><p>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x6309;&#x7167;CICD&#x7684;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x5C06;CI_Config&#x76EE;&#x5F55;&#x521B;&#x5EFA;&#x5728;&#x4E86;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x4E0B;&#x56FE;&#x4E2D;&#x7684;&#x4F8B;&#x5916;&#x8DEF;&#x5F84;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x9ED8;&#x8BA4;&#x4E0D;&#x586B;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5C06;CI_Config&#x76EE;&#x5F55;&#x6309;&#x7167;&#x7EA6;&#x5B9A;&#x8BBE;&#x7F6E;&#x5728;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x5219;&#x9700;&#x8981;&#x5728;&#x6B64;&#x91CD;&#x65B0;&#x8BBE;&#x7F6E;&#x8DEF;&#x5F84;&#xFF0C;&#x5E76;&#x4E14;&#x6253;&#x5F00;es6&#x68C0;&#x6D4B;&#x914D;&#x7F6E;&#x9879;</p>
<p><img src="picture/cicd10.png" alt="cicd10"></p>
</li>
</ul>
</li>
<li><p>&#x627E;&#x5230;&#x521B;&#x5EFA;&#x7684;&#x6D41;&#x7A0B;&#x70B9;&#x51FB;&#x6784;&#x5EFA;&#xFF0C;&#x7B49;&#x5F85;&#x6D41;&#x7A0B;&#x6784;&#x5EFA;&#x5B8C;&#x6BD5;&#xFF0C;&#x5728;&#x4E0B;&#x65B9;&#x627E;&#x5230;&#x5BF9;&#x5E94;&#x7684;&#x68C0;&#x6D4B;&#x7ED3;&#x679C;&#xFF0C;&#x70B9;&#x51FB;&#x5373;&#x53EF;&#x67E5;&#x770B;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</p>
<p><img src="picture/cicd8.png" alt="cicd8"></p>
<p><img src="picture/cicd9.png" alt="cicd9"></p>
</li>
</ol>
<h1 id="ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;"><a name="ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#ide&#x5DE5;&#x5177;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>25. IDE&#x5DE5;&#x5177;&#x914D;&#x7F6E;</h1>
<p>  Visual Studio Code (&#x7B80;&#x79F0; VSCode / VSC) &#x662F;&#x4E00;&#x6B3E;&#x514D;&#x8D39;&#x5F00;&#x6E90;&#x7684;&#x73B0;&#x4EE3;&#x5316;&#x8F7B;&#x91CF;&#x7EA7;&#x4EE3;&#x7801;&#x7F16;&#x8F91;&#x5668;&#xFF0C;&#x8F6F;&#x4EF6;&#x8DE8;&#x5E73;&#x53F0;&#x652F;&#x6301; Win&#x3001;Mac &#x4EE5;&#x53CA; Linux&#xFF0C;&#x8FD0;&#x884C;&#x6D41;&#x7545;&#xFF0C;&#x5E76;&#x4E14;&#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x4E30;&#x5BCC;&#x7684;&#x6269;&#x5C55;&#x5DE5;&#x5177;&#xFF0C;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x5B83;&#x4F5C;&#x4E3A;&#x6211;&#x4EEC;&#x524D;&#x7AEF;&#x5F00;&#x53D1;&#x7684;&#x5DE5;&#x5177;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5C06;&#x4ECB;&#x7ECD;&#x5982;&#x4F55;&#x5728;VSCode&#x5185;&#x914D;&#x7F6E;&#x5B9E;&#x65F6;&#x68C0;&#x6D4B;&#x548C;&#x4E00;&#x952E;&#x683C;&#x5F0F;&#x5316;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<ul>
<li><p>&#x5B9E;&#x65F6;&#x68C0;&#x6D4B;&#x529F;&#x80FD;&#x914D;&#x7F6E;&#x6B65;&#x9AA4;&#xFF1A;</p>
<ol>
<li><p>&#x9996;&#x5148;&#x9700;&#x8981;&#x8FDB;&#x5165;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#xFF08;cmd&#xFF09;&#x5168;&#x5C40;&#x5B89;&#x88C5;<code>fish</code>&#x7684;<code>eslint</code>&#x89C4;&#x5219;&#x5305;&#xFF0C;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-bash"> $ npm i -g @whalecloud/eslint-config eslint@5.16.0 --registry http://registry.npm.ztesoft.com
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;VSCode&#x6253;&#x5F00;&#x9879;&#x76EE;&#xFF0C;&#x70B9;&#x51FB;VSCode&#x53F3;&#x4FA7;&#x5DE5;&#x5177;&#x680F;&#x4E2D;&#x7684;&#x6269;&#x5C55;&#x9009;&#x9879;&#xFF0C;&#x641C;&#x7D22;eslint&#xFF0C;&#x70B9;&#x51FB;&#x5B89;&#x88C5;</p>
<p><img src="picture/tool1.png" alt="tool1"></p>
</li>
<li><p>&#x5B89;&#x88C5;&#x5B8C;&#x6210;&#x540E;&#x91CD;&#x65B0;&#x6253;&#x5F00;VSCode&#x5373;&#x53EF;&#x5728;&#x7F16;&#x5199;js&#x4EE3;&#x7801;&#x65F6;&#x5B9E;&#x65F6;&#x68C0;&#x6D4B;&#x4E0D;&#x7B26;&#x5408;&#x89C4;&#x8303;&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x5E76;&#x7ED9;&#x51FA;&#x6807;&#x7EA2;&#x63D0;&#x793A;</p>
<p><img src="picture/tool2.png" alt="tool2"></p>
</li>
</ol>
</li>
<li><p>&#x4E00;&#x952E;&#x683C;&#x5F0F;&#x5316;&#x529F;&#x80FD;&#x914D;&#x7F6E;&#xFF1A;</p>
<ol>
<li><p>&#x4F7F;&#x7528;VSCode&#x6253;&#x5F00;&#x9879;&#x76EE;&#xFF0C;&#x70B9;&#x51FB;VSCode&#x53F3;&#x4FA7;&#x5DE5;&#x5177;&#x680F;&#x4E2D;&#x7684;&#x6269;&#x5C55;&#x9009;&#x9879;&#xFF0C;&#x641C;&#x7D22;prettier&#xFF0C;&#x70B9;&#x51FB;&#x5B89;&#x88C5;</p>
<p><img src="picture/tool3.png" alt="tool3"></p>
</li>
<li><p>&#x70B9;&#x51FB;VSCode&#x53F3;&#x4FA7;&#x5DE5;&#x5177;&#x680F;&#x4E2D;&#x7684;&#x6269;&#x5C55;&#x9009;&#x9879;&#xFF0C;&#x641C;&#x7D22;editorConfig&#xFF0C;&#x70B9;&#x51FB;&#x5B89;&#x88C5;</p>
<p><img src="picture/tool4.png" alt="tool4"></p>
</li>
</ol>
</li>
</ul>
<ol>
<li><p>&#x91CD;&#x65B0;&#x6253;&#x5F00;&#x9879;&#x76EE;&#x627E;&#x5230;&#x9700;&#x8981;&#x683C;&#x5F0F;&#x5316;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x53F3;&#x952E;&#x9009;&#x62E9;&#x683C;&#x5F0F;&#x5316;&#x6587;&#x6863;&#xFF08;&#x5FEB;&#x6377;&#x952E;&#xFF1A;Shift+Alt+F)&#xFF0C;&#x5373;&#x53EF;&#x4E00;&#x952E;&#x89E3;&#x51B3;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x7A7A;&#x683C;&#x3001;&#x9017;&#x53F7;&#x3001;&#x5F15;&#x53F7;&#x3001;&#x5355;&#x884C;&#x957F;&#x5EA6;&#x7B49;&#x683C;&#x5F0F;&#x95EE;&#x9898;</p>
<p><img src="picture/tool5.png" alt="tool4"></p>
</li>
</ol>
<ul>
<li><p>&#x6E29;&#x99A8;&#x63D0;&#x793A;&#xFF1A;&#x4EE5;&#x4E0A;&#x5DE5;&#x5177;&#x7684;&#x4F7F;&#x7528;&#x9700;&#x8981;&#x5728;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E2D;&#x6709;<code>.eslintrc.js</code>&#x548C;<code>.prettierrc</code>&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;fish-cli&#x521B;&#x5EFA;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x90FD;&#x4F1A;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5F53;&#x7136;&#x5982;&#x679C;&#x4F60;&#x5DF2;&#x7ECF;&#x6309;&#x7167;&#x4E0A;&#x9762;&#x7684;&#x5DE5;&#x5177;&#x5B89;&#x88C5;&#x4E86;fish-cli&#x5E76;&#x4E14;&#x4F7F;&#x7528;&#x7684;<code>fish es6lint</code>&#x547D;&#x4EE4;&#x5BF9;&#x9879;&#x76EE;&#x8FDB;&#x884C;&#x4E86;&#x68C0;&#x6D4B;&#xFF0C;&#x8FD9;&#x65F6;&#x4E5F;&#x4F1A;&#x5728;&#x4F60;&#x76F8;&#x5E94;&#x7684;&#x76EE;&#x5F55;&#x4E2D;&#x751F;&#x6210;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5177;&#x4F53;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF0C;&#x8BF7;&#x786E;&#x4FDD;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x4E0E;&#x6B64;&#x76F8;&#x540C;&#xFF1A;</p>
<p> <img src="picture/tool6.png" alt="tool5"></p>
<p> <img src="picture/tool7.png" alt="tool6"></p>
<p> <img src="picture/editorconfig.png" alt="editorconfig"></p>
</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="JavaScript_ES5_ReleasedVersion.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: ES5规范">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ES6规范","level":"1.1.9.2","depth":3,"next":{"title":"安全规范及规定","level":"1.1.10","depth":2,"ref":"","articles":[{"title":"产品安全红线管理规定","level":"1.1.10.1","depth":3,"path":"security/Security_Redline/Security_Redline_ReleasedVersion.md","ref":"security/Security_Redline/Security_Redline_ReleasedVersion.md","articles":[]},{"title":"产品设计安全规范","level":"1.1.10.2","depth":3,"path":"security/Security_Design/Security_Design_ReleasedVersion.md","ref":"security/Security_Design/Security_Design_ReleasedVersion.md","articles":[]},{"title":"产品研发安全规范","level":"1.1.10.3","depth":3,"path":"security/R&D_Security/R&D_Security_ReleasedVersion.md","ref":"security/R&D_Security/R&D_Security_ReleasedVersion.md","articles":[]},{"title":"交付运维安全规范","level":"1.1.10.4","depth":3,"path":"security/O&M_Security/O&M_Security_ReleasedVersion.md","ref":"security/O&M_Security/O&M_Security_ReleasedVersion.md","articles":[]},{"title":"开源软件管理规范","level":"1.1.10.5","depth":3,"path":"security/OSS_Management/PG_OSS_Management_ReleasedVersion.md","ref":"security/OSS_Management/PG_OSS_Management_ReleasedVersion.md","articles":[]}]},"previous":{"title":"ES5规范","level":"1.1.9.1","depth":3,"path":"Language/JavaScript/JavaScript_ES5_ReleasedVersion.md","ref":"Language/JavaScript/JavaScript_ES5_ReleasedVersion.md","articles":[]},"dir":"ltr"},"config":{"plugins":["edit-link","copy-code-button","-lunr","-search","search-pro","anchor-navigation-ex","splitter","emphasize"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"search-pro":{},"page-toc":{"maxDepth":5,"position":"before-first","showByDefault":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"mode":"float","pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"isRewritePageTitle":true,"showLevel":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right","showGoTop":true,"isShowTocTitleIcon":true,"tocLevel4Icon":"fa fa-hand-o-right","tocLevel5Icon":"fa fa-hand-o-right","printLog":false,"multipleH1":true,"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false}},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"http://gitlab.iwhalecloud.com/CoP/sql_new/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Sqlrule","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Sqlrule","gitbook":"3.2.3"},"file":{"path":"Language/JavaScript/JavaScript_ES6_ReleasedVersion.md","mtime":"2022-04-18T07:38:53.887Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-18T07:39:41.387Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="js/gitbook.js"></script>
    <script src="js/theme.js"></script>
    
        
        <script src="js/plugin.js"></script>
        
    
        
        <script src="js/toggle.js"></script>
        
    
        
        <script src="js/jquery.mark.min.js"></script>
        
    
        
        <script src="js/search.js"></script>
        
    
        
        <script src="js/splitter.js"></script>
        
    
        
        <script src="js/buttons.js"></script>
        
    
        
        <script src="js/fontsettings.js"></script>
        
    

    </body>
</html>

